diff options
| author | Méven Car <[email protected]> | 2019-04-14 16:54:54 +0200 |
|---|---|---|
| committer | Méven Car <[email protected]> | 2019-06-23 16:38:09 +0200 |
| commit | e6c1b97d67f6b6c6d4ad935db14241b041b3fca4 (patch) | |
| tree | f0325a8b9ce9836b9e2149fcfd90ac23b0f044f5 /src/panels/information/phononwidget.cpp | |
| parent | cdad6a513e2cbd4376dd03bb4fa63681076eb18b (diff) | |
Allow dolphin to auto-play previewed media file, click on preview to play/pause videos or audio
Summary:
It is based on D19844.
I did my best to avoid glitches hence the amount of code touched.
Retry after @pekkah D7539
Moved the setting to the information panel context menu, no more timer
Settings screenshot :
{F6700220}
This would mach the same feature in the open/save dialog (although not equivalent)
{F6696456}
FEATURE: 378613
FIXED-IN: 19.08.0
GUI: New information panel context menu option
Test Plan:
Without auto play
- in dolphin with the information panel opened, and the auto media play feature is disabled (right on the information panel)
- hover over media files
- the behavior is the same as before the patch
With auto play
- in dolphin with the information panel opened, and the auto media play feature is enabled
- hover over media files
- media is played automatically
- hover over another media file, the new media is previewed
Use audio or video file as media.
Reviewers: #dolphin, elvisangelaccio, ngraham
Reviewed By: #dolphin, elvisangelaccio, ngraham
Subscribers: ngraham, broulik, kfm-devel, pekkah
Tags: #dolphin
Differential Revision: https://phabricator.kde.org/D19782
Diffstat (limited to 'src/panels/information/phononwidget.cpp')
| -rw-r--r-- | src/panels/information/phononwidget.cpp | 56 |
1 files changed, 35 insertions, 21 deletions
diff --git a/src/panels/information/phononwidget.cpp b/src/panels/information/phononwidget.cpp index 77e066d37..4ea2e6666 100644 --- a/src/panels/information/phononwidget.cpp +++ b/src/panels/information/phononwidget.cpp @@ -69,11 +69,24 @@ PhononWidget::PhononWidget(QWidget *parent) { } -void PhononWidget::setUrl(const QUrl &url) +void PhononWidget::setUrl(const QUrl &url, MediaKind kind) { if (m_url != url) { - stop(); // emits playingStopped() signal m_url = url; + m_isVideo = kind == MediaKind::Video; + } + if (m_autoPlay) { + play(); + } else { + stop(); + } +} + +void PhononWidget::setAutoPlay(bool autoPlay) +{ + m_autoPlay = autoPlay; + if (!m_url.isEmpty() && (m_media == nullptr || m_media->state() != Phonon::State::PlayingState) && m_autoPlay && isVisible()) { + play(); } } @@ -162,12 +175,6 @@ void PhononWidget::stateChanged(Phonon::State newstate) m_stopButton->show(); m_playButton->hide(); break; - case Phonon::StoppedState: - if (m_videoPlayer) { - m_videoPlayer->hide(); - } - emit hasVideoChanged(false); - Q_FALLTHROUGH(); default: m_stopButton->hide(); m_playButton->show(); @@ -182,13 +189,14 @@ void PhononWidget::play() m_media = new Phonon::MediaObject(this); connect(m_media, &Phonon::MediaObject::stateChanged, this, &PhononWidget::stateChanged); - connect(m_media, &Phonon::MediaObject::hasVideoChanged, - this, &PhononWidget::slotHasVideoChanged); + connect(m_media, &Phonon::MediaObject::finished, + this, &PhononWidget::finished); m_seekSlider->setMediaObject(m_media); } if (!m_videoPlayer) { m_videoPlayer = new EmbeddedVideoPlayer(this); + m_videoPlayer->installEventFilter(this); m_topLayout->insertWidget(0, m_videoPlayer); Phonon::createPath(m_media, m_videoPlayer); applyVideoSize(); @@ -199,26 +207,32 @@ void PhononWidget::play() Phonon::createPath(m_media, m_audioOutput); } - emit hasVideoChanged(false); + if (m_isVideo) { + emit hasVideoChanged(true); + } - m_media->setCurrentSource(m_url); - m_media->hasVideo(); + if (m_url != m_media->currentSource().url()) { + m_media->setCurrentSource(m_url); + } m_media->play(); + + m_videoPlayer->setVisible(m_isVideo); } -void PhononWidget::stop() +void PhononWidget::finished() { - if (m_media) { - m_media->stop(); + if (m_isVideo) { + m_videoPlayer->hide(); + emit hasVideoChanged(false); } } -void PhononWidget::slotHasVideoChanged(bool hasVideo) +void PhononWidget::stop() { - emit hasVideoChanged(hasVideo); - - if (hasVideo) { - m_videoPlayer->show(); + if (m_media) { + m_media->stop(); + m_videoPlayer->hide(); + emit hasVideoChanged(false); } } |
