]> cloud.milkyroute.net Git - dolphin.git/blobdiff - src/panels/information/phononwidget.cpp
Show video previews according to file content instead of the mimetype-string
[dolphin.git] / src / panels / information / phononwidget.cpp
index 5f0c1115827f37de817d3cf32a3c5d35b21e4e2b..1419f68be9b80e425b08b59285458db22817a93a 100644 (file)
 
 #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>
 #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()