diff options
| author | Peter Penz <[email protected]> | 2012-05-19 22:27:53 +0200 |
|---|---|---|
| committer | Peter Penz <[email protected]> | 2012-05-19 22:30:31 +0200 |
| commit | c318a3da6c79c35b4d3ba3043d71228cbeda64f8 (patch) | |
| tree | b4cec1654cc109e381b4ac60e1daac4bb550b0f7 /src/panels/information/phononwidget.cpp | |
| parent | e9d29bcf30ccbd7c76ba37ce9efcfac1649fc46e (diff) | |
Show video previews according to file content instead of the mimetype-string
Show a video widget depending on the video content instead of the mimetype
string: There are container formats which can be either audios or videos.
Besides, the rmvb video files have a mimetype of
"application/vnd.rn-realmedia", and these files can be recognized as videos
correctly now.
The patch has been provided by Hui Ni.
REVIEW: 104988
FIXED-IN: 4.9
Diffstat (limited to 'src/panels/information/phononwidget.cpp')
| -rw-r--r-- | src/panels/information/phononwidget.cpp | 93 |
1 files changed, 42 insertions, 51 deletions
diff --git a/src/panels/information/phononwidget.cpp b/src/panels/information/phononwidget.cpp index 5f0c11158..1419f68be 100644 --- a/src/panels/information/phononwidget.cpp +++ b/src/panels/information/phononwidget.cpp @@ -20,10 +20,11 @@ #include "phononwidget.h" +#include <Phonon/AudioOutput> #include <Phonon/Global> #include <Phonon/MediaObject> #include <Phonon/SeekSlider> -#include <Phonon/VideoPlayer> +#include <Phonon/VideoWidget> #include <QVBoxLayout> #include <QHBoxLayout> @@ -35,11 +36,11 @@ #include <KUrl> #include <KLocale> -class EmbeddedVideoPlayer : public Phonon::VideoPlayer +class EmbeddedVideoPlayer : public Phonon::VideoWidget { public: - EmbeddedVideoPlayer(Phonon::Category category, QWidget *parent = 0) : - Phonon::VideoPlayer(category, parent) + EmbeddedVideoPlayer(QWidget *parent = 0) : + Phonon::VideoWidget(parent) { } @@ -51,7 +52,7 @@ class EmbeddedVideoPlayer : public Phonon::VideoPlayer virtual QSize sizeHint() const { - return m_sizeHint.isValid() ? m_sizeHint : Phonon::VideoPlayer::sizeHint(); + return m_sizeHint.isValid() ? m_sizeHint : Phonon::VideoWidget::sizeHint(); } private: @@ -60,14 +61,13 @@ class EmbeddedVideoPlayer : public Phonon::VideoPlayer PhononWidget::PhononWidget(QWidget *parent) : QWidget(parent), - m_mode(Audio), m_url(), m_playButton(0), m_stopButton(0), m_topLayout(0), - m_audioMedia(0), m_media(0), m_seekSlider(0), + m_audioOutput(0), m_videoPlayer(0) { } @@ -85,19 +85,6 @@ KUrl PhononWidget::url() const return m_url; } -void PhononWidget::setMode(Mode mode) -{ - if (m_mode != mode) { - stop(); // emits playingStopped() signal - m_mode = mode; - } -} - -PhononWidget::Mode PhononWidget::mode() const -{ - return m_mode; -} - void PhononWidget::setVideoSize(const QSize& size) { if (m_videoSize != size) { @@ -183,47 +170,31 @@ void PhononWidget::stateChanged(Phonon::State newstate) void PhononWidget::play() { - switch (m_mode) { - case Audio: - if (!m_audioMedia) { - m_audioMedia = Phonon::createPlayer(Phonon::MusicCategory, m_url); - m_audioMedia->setParent(this); - } - m_media = m_audioMedia; - m_media->setCurrentSource(m_url); - m_media->play(); - break; - - case Video: - if (!m_videoPlayer) { - m_videoPlayer = new EmbeddedVideoPlayer(Phonon::VideoCategory, this); - m_topLayout->insertWidget(0, m_videoPlayer); - } - applyVideoSize(); - m_videoPlayer->show(); - m_videoPlayer->play(m_url); - m_media = m_videoPlayer->mediaObject(); - break; + if (!m_media) { + m_media = new Phonon::MediaObject(this); + connect(m_media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), + this, SLOT(stateChanged(Phonon::State))); + connect(m_media, SIGNAL(hasVideoChanged(bool)), + this, SLOT(slotHasVideoChanged(bool))); + m_seekSlider->setMediaObject(m_media); + } - default: - break; + if (!m_audioOutput) { + m_audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory, this); + Phonon::createPath(m_media, m_audioOutput); } - Q_ASSERT(m_media); - connect(m_media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this, SLOT(stateChanged(Phonon::State))); - m_seekSlider->setMediaObject(m_media); + emit hasVideoChanged(false); - emit playingStarted(); + m_media->setCurrentSource(m_url); + m_media->hasVideo(); + m_media->play(); } void PhononWidget::stop() { if (m_media) { m_media->stop(); - disconnect(m_media, SIGNAL(stateChanged(Phonon::State,Phonon::State)), - this, SLOT(stateChanged(Phonon::State))); - emit playingStopped(); m_stopButton->hide(); m_playButton->show(); @@ -232,6 +203,26 @@ void PhononWidget::stop() if (m_videoPlayer) { m_videoPlayer->hide(); } + + emit hasVideoChanged(false); +} + +void PhononWidget::slotHasVideoChanged(bool hasVideo) +{ + emit hasVideoChanged(hasVideo); + + if (hasVideo) { + if (!m_videoPlayer) { + // Replay the media to apply path changes + m_media->stop(); + m_videoPlayer = new EmbeddedVideoPlayer(this); + m_topLayout->insertWidget(0, m_videoPlayer); + Phonon::createPath(m_media, m_videoPlayer); + m_media->play(); + } + applyVideoSize(); + m_videoPlayer->show(); + } } void PhononWidget::applyVideoSize() |
