]> git.sur5r.net Git - minitube/commitdiff
Handle invalid finished signals from Phonon
authorFlavio <flavio@odisseo.local>
Sat, 29 Jan 2011 21:12:05 +0000 (22:12 +0100)
committerFlavio <flavio@odisseo.local>
Sat, 29 Jan 2011 21:12:05 +0000 (22:12 +0100)
src/MediaView.cpp
src/MediaView.h

index 44e7078d212273ea1043d3da843cbcaa612d5a70..0fd49b27ca97eebfd944133661b8357fe9a9ed6f 100644 (file)
@@ -140,12 +140,12 @@ void MediaView::initialize() {
 void MediaView::setMediaObject(Phonon::MediaObject *mediaObject) {
     this->mediaObject = mediaObject;
     Phonon::createPath(this->mediaObject, videoWidget);
-    connect(mediaObject, SIGNAL(finished()), this, SLOT(skip()));
+    connect(mediaObject, SIGNAL(finished()), this, SLOT(playbackFinished()));
     connect(mediaObject, SIGNAL(stateChanged(Phonon::State, Phonon::State)),
             this, SLOT(stateChanged(Phonon::State, Phonon::State)));
     connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)),
             this, SLOT(currentSourceChanged(Phonon::MediaSource)));
-    connect(mediaObject, SIGNAL(bufferStatus(int)), loadingWidget, SLOT(bufferStatus(int)));
+    // connect(mediaObject, SIGNAL(bufferStatus(int)), loadingWidget, SLOT(bufferStatus(int)));
 }
 
 void MediaView::search(SearchParams *searchParams) {
@@ -214,12 +214,12 @@ void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/)
         break;
 
     case Phonon::PlayingState:
-        qDebug("playing");
+        // qDebug("playing");
         videoAreaWidget->showVideo();
         break;
 
     case Phonon::StoppedState:
-        qDebug("stopped");
+        // qDebug("stopped");
         // play() has already been called when setting the source
         // but Phonon on Linux needs a little more help to start playback
         // if (!reallyStopped) mediaObject->play();
@@ -342,7 +342,10 @@ void MediaView::gotStreamUrl(QUrl streamUrl) {
     downloadItem = new DownloadItem(videoCopy, streamUrl, tempFile, this);
     connect(downloadItem, SIGNAL(statusChanged()), SLOT(downloadStatusChanged()));
     // connect(downloadItem, SIGNAL(progress(int)), SLOT(downloadProgress(int)));
+    connect(downloadItem, SIGNAL(bufferProgress(int)), loadingWidget, SLOT(bufferStatus(int)));
     // connect(downloadItem, SIGNAL(finished()), SLOT(itemFinished()));
+    connect(video, SIGNAL(errorStreamUrl(QString)), SLOT(handleError(QString)));
+    connect(downloadItem, SIGNAL(error(QString)), SLOT(handleError(QString)));
     downloadItem->start();
 
 }
@@ -381,15 +384,16 @@ void MediaView::downloadStatusChanged() {
         startPlaying();
         break;
     case Starting:
-        qDebug() << "Starting";
+        // qDebug() << "Starting";
         break;
     case Finished:
-        qDebug() << "Finished";
+        // qDebug() << "Finished" << mediaObject->state();
+        // if (mediaObject->state() == Phonon::StoppedState) startPlaying();
         break;
     case Failed:
-        qDebug() << "Failed";
+        // qDebug() << "Failed";
     case Idle:
-        qDebug() << "Idle";
+        // qDebug() << "Idle";
         break;
     }
 }
@@ -451,6 +455,18 @@ void MediaView::skip() {
     listModel->setActiveRow(nextRow);
 }
 
+void MediaView::playbackFinished() {
+    if (mediaObject->currentTime() < mediaObject->totalTime()) {
+        // mediaObject->seek(mediaObject->currentTime());
+        QTimer::singleShot(3000, this, SLOT(playbackResume()));
+    } else skip();
+}
+
+void MediaView::playbackResume() {
+    mediaObject->seek(mediaObject->currentTime());
+    mediaObject->play();
+}
+
 void MediaView::openWebPage() {
     Video* video = listModel->activeVideo();
     if (!video) return;
index f61799a7806ac4072fd4dc95ecf827337e1fdb2a..a4016bee1b60775b7535e081e1df22089095ff5b 100644 (file)
@@ -83,6 +83,8 @@ private slots:
 #endif
     void startPlaying();
     void downloadStatusChanged();
+    void playbackFinished();
+    void playbackResume();
 
     /*
     void downloadProgress(int percent);