Blackberry: Fix case of setting multiple media files
authorThomas McGuire <thomas.mcguire.qnx@kdab.com>
Thu, 26 Jul 2012 14:02:57 +0000 (16:02 +0200)
committerQt by Nokia <qt-info@nokia.com>
Sat, 28 Jul 2012 15:21:43 +0000 (17:21 +0200)
Abort the singleshot timer when the media is changed, as otherwise
continueLoadMedia() was called multiple times.
Also, don't use a singleshot timer when setting a null media.

Change-Id: I19d4838c9c70e7fcaa790c223cb19ac3e0246e6b
Reviewed-by: Kevin Krammer <kevin.krammer@kdab.com>
Reviewed-by: Sean Harmer <sean.harmer@kdab.com>
src/plugins/blackberry/bbmediaplayercontrol.cpp
src/plugins/blackberry/bbmediaplayercontrol.h

index 63437fc..3a84149 100644 (file)
@@ -45,7 +45,6 @@
 #include <QtCore/qcoreapplication.h>
 #include <QtCore/qdir.h>
 #include <QtCore/qfileinfo.h>
-#include <QtCore/qtimer.h>
 #include <QtCore/quuid.h>
 #include <mm/renderer.h>
 #include <bps/mmrenderer.h>
@@ -84,6 +83,9 @@ BbMediaPlayerControl::BbMediaPlayerControl(QObject *parent)
       m_stopEventsToIgnore(0),
       m_bufferStatus(0)
 {
+    m_loadingTimer.setSingleShot(true);
+    m_loadingTimer.setInterval(0);
+    connect(&m_loadingTimer, SIGNAL(timeout()), this, SLOT(continueLoadMedia()));
     QCoreApplication::eventDispatcher()->installNativeEventFilter(this);
     openConnection();
 }
@@ -221,6 +223,7 @@ void BbMediaPlayerControl::detach()
         QFile::remove(m_tempMediaFileName);
         m_tempMediaFileName.clear();
     }
+    m_loadingTimer.stop();
 }
 
 QMediaPlayer::State BbMediaPlayerControl::state() const
@@ -423,8 +426,12 @@ void BbMediaPlayerControl::setMedia(const QMediaContent &media, QIODevice *strea
     // canvas is ready.
     // The mmrenderer doesn't allow to attach video outputs after playing has started, otherwise
     // this would be unnecessary.
-    setMediaStatus(QMediaPlayer::LoadingMedia);
-    QTimer::singleShot(0, this, SLOT(continueLoadMedia()));
+    if (!m_media.isNull()) {
+        setMediaStatus(QMediaPlayer::LoadingMedia);
+        m_loadingTimer.start(); // singleshot timer to continueLoadMedia()
+    } else {
+        continueLoadMedia(); // still needed, as it will update the media status and clear metadata
+    }
 }
 
 void BbMediaPlayerControl::continueLoadMedia()
index 519a435..e8a9ed8 100644 (file)
@@ -45,6 +45,7 @@
 #include <qmediaplayercontrol.h>
 #include <QtCore/qabstractnativeeventfilter.h>
 #include <QtCore/qpointer.h>
+#include <QtCore/qtimer.h>
 
 struct bps_event_t;
 typedef struct mmr_connection mmr_connection_t;
@@ -145,6 +146,7 @@ private:
     int m_stopEventsToIgnore;
     int m_bufferStatus;
     QString m_tempMediaFileName;
+    QTimer m_loadingTimer;
 };
 
 QT_END_NAMESPACE