]> git.sur5r.net Git - minitube/commitdiff
Get a new stream url after long pause
authorFlavio Tordini <flavio.tordini@gmail.com>
Mon, 3 Aug 2015 13:45:19 +0000 (15:45 +0200)
committerFlavio Tordini <flavio.tordini@gmail.com>
Mon, 3 Aug 2015 13:45:19 +0000 (15:45 +0200)
src/mediaview.cpp
src/mediaview.h

index 08798bf481ddbb7cf3c4ea9647e358602b754bb2..a2c4587cc17e231eb52c4934071a244c9403c189 100644 (file)
@@ -70,6 +70,7 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent)
   #ifdef APP_SNAPSHOT
   , snapshotSettings(0)
   #endif
+  , pauseTime(0)
 { }
 
 void MediaView::initialize() {
@@ -322,9 +323,13 @@ void MediaView::handleError(const QString &message) {
 
 #ifdef APP_PHONON
 void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) {
-    if (newState == Phonon::PlayingState)
+    if (pauseTime > 0 && (newState == Phonon::PlayingState || newState == Phonon::BufferingState)) {
+        mediaObject->seek(pauseTime);
+        pauseTime = 0;
+    }
+    if (newState == Phonon::PlayingState) {
         videoAreaWidget->showVideo();
-    else if (newState == Phonon::ErrorState) {
+    else if (newState == Phonon::ErrorState) {
         qWarning() << "Phonon error:" << mediaObject->errorString() << mediaObject->errorType();
         if (mediaObject->errorType() == Phonon::FatalError)
             handleError(mediaObject->errorString());
@@ -337,9 +342,14 @@ void MediaView::pause() {
     switch( mediaObject->state() ) {
     case Phonon::PlayingState:
         mediaObject->pause();
+        pauseTimer.start();
         break;
     default:
-        mediaObject->play();
+        if (pauseTimer.hasExpired(60000)) {
+            pauseTimer.invalidate();
+            connect(playlistModel->activeVideo(), SIGNAL(gotStreamUrl(QUrl)), SLOT(resumeWithNewStreamUrl(QUrl)));
+            playlistModel->activeVideo()->loadStreamUrl();
+        } else mediaObject->play();
         break;
     }
 #endif
@@ -905,6 +915,19 @@ void MediaView::startDownloading() {
     downloadItem->start();
 }
 
+void MediaView::resumeWithNewStreamUrl(const QUrl &streamUrl) {
+    pauseTime = mediaObject->currentTime();
+    mediaObject->setCurrentSource(streamUrl);
+    mediaObject->play();
+
+    Video *video = static_cast<Video *>(sender());
+    if (!video) {
+        qDebug() << "Cannot get sender in" << __PRETTY_FUNCTION__;
+        return;
+    }
+    video->disconnect(this);
+}
+
 void MediaView::maybeAdjustWindowSize() {
     QSettings settings;
     if (settings.value("adjustWindowSize", true).toBool())
index 41ec3cc76225e028134bdd1cc041821ae7d5ee8c..468d32ef72ab90950adc25119f91d4a2abf161b7 100644 (file)
@@ -134,6 +134,7 @@ private slots:
     void sliderMoved(int value);
     qint64 offsetToTime(qint64 offset);
     void startDownloading();
+    void resumeWithNewStreamUrl(const QUrl &streamUrl);
 
 private:
     MediaView(QWidget *parent = 0);
@@ -171,6 +172,9 @@ private:
 #ifdef APP_SNAPSHOT
     SnapshotSettings *snapshotSettings;
 #endif
+
+    QElapsedTimer pauseTimer;
+    qint64 pauseTime;
 };
 
 #endif // __MEDIAVIEW_H__