From 6094fb9317cd8e968a1577520344daa249aaae07 Mon Sep 17 00:00:00 2001 From: Flavio Date: Sun, 10 Jun 2012 16:23:00 +0200 Subject: [PATCH] Workaround for new Phonon GStreamer quirk --- src/MediaView.cpp | 32 +++++++++++++++++++++++++------- src/MediaView.h | 5 ++++- 2 files changed, 29 insertions(+), 8 deletions(-) diff --git a/src/MediaView.cpp b/src/MediaView.cpp index c892c7b..2418db6 100644 --- a/src/MediaView.cpp +++ b/src/MediaView.cpp @@ -91,9 +91,9 @@ MediaView::MediaView(QWidget *parent) : QWidget(parent) { splitter->addWidget(playlistWidget); videoAreaWidget = new VideoAreaWidget(this); - videoAreaWidget->setMinimumSize(320,240); + // videoAreaWidget->setMinimumSize(320,240); -#ifdef APP_MAC_NO +#ifdef APP_MAC // mouse autohide does not work on the Mac (no mouseMoveEvent) videoWidget = new Phonon::VideoWidget(this); #else @@ -155,6 +155,7 @@ void MediaView::setMediaObject(Phonon::MediaObject *mediaObject) { connect(mediaObject, SIGNAL(currentSourceChanged(Phonon::MediaSource)), this, SLOT(currentSourceChanged(Phonon::MediaSource))); // connect(mediaObject, SIGNAL(bufferStatus(int)), loadingWidget, SLOT(bufferStatus(int))); + connect(mediaObject, SIGNAL(aboutToFinish()), SLOT(aboutToFinish())); } void MediaView::search(SearchParams *searchParams) { @@ -197,7 +198,7 @@ void MediaView::disappear() { void MediaView::handleError(QString /* message */) { - QTimer::singleShot(100, this, SLOT(startPlaying())); + QTimer::singleShot(500, this, SLOT(startPlaying())); /* videoAreaWidget->showError(message); @@ -207,10 +208,8 @@ void MediaView::handleError(QString /* message */) { */ } -void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) -{ - - // qDebug() << "Phonon state: " << newState << oldState; +void MediaView::stateChanged(Phonon::State newState, Phonon::State /*oldState*/) { + // qDebug() << "Phonon state: " << newState; // slider->setEnabled(newState == Phonon::PlayingState); switch (newState) { @@ -409,6 +408,9 @@ void MediaView::downloadStatusChanged() { case Finished: // qDebug() << "Finished" << mediaObject->state(); // if (mediaObject->state() == Phonon::StoppedState) startPlaying(); +#ifdef Q_WS_X11 + seekSlider->setEnabled(mediaObject->isSeekable()); +#endif break; case Failed: // qDebug() << "Failed"; @@ -430,6 +432,9 @@ void MediaView::startPlaying() { qDebug() << "Playing" << source; mediaObject->setCurrentSource(source); mediaObject->play(); +#ifdef Q_WS_X11 + seekSlider->setEnabled(false); +#endif // ensure we always have 10 videos ahead listModel->searchNeeded(); @@ -497,7 +502,19 @@ void MediaView::skipBackward() { listModel->setActiveRow(prevRow); } +void MediaView::aboutToFinish() { + qint64 currentTime = mediaObject->currentTime(); + qDebug() << __PRETTY_FUNCTION__ << currentTime; + if (currentTime + 10000 < mediaObject->totalTime()) { + // mediaObject->seek(mediaObject->currentTime()); + // QTimer::singleShot(500, this, SLOT(playbackResume())); + mediaObject->seek(currentTime); + mediaObject->play(); + } +} + void MediaView::playbackFinished() { + qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime(); // qDebug() << "finished" << mediaObject->currentTime() << mediaObject->totalTime(); // add 10 secs for imprecise Phonon backends (VLC, Xine) if (mediaObject->currentTime() + 10000 < mediaObject->totalTime()) { @@ -512,6 +529,7 @@ void MediaView::playbackFinished() { } void MediaView::playbackResume() { + qDebug() << __PRETTY_FUNCTION__ << mediaObject->currentTime(); mediaObject->seek(mediaObject->currentTime()); mediaObject->play(); } diff --git a/src/MediaView.h b/src/MediaView.h index c6deee1..8bf2c8d 100644 --- a/src/MediaView.h +++ b/src/MediaView.h @@ -5,6 +5,7 @@ #include #include #include +#include #include "View.h" #include "ListModel.h" #include "segmentedcontrol.h" @@ -40,7 +41,7 @@ public: } void setMediaObject(Phonon::MediaObject *mediaObject); - void setSlider(QSlider *slider); + void setSlider(Phonon::SeekSlider *slider) { this->seekSlider = slider; } public slots: void search(SearchParams *searchParams); @@ -76,6 +77,7 @@ private slots: void stateChanged(Phonon::State newState, Phonon::State oldState); void currentSourceChanged(const Phonon::MediaSource source); void showVideoContextMenu(QPoint point); + void aboutToFinish(); // bar void searchMostRelevant(); void searchMostRecent(); @@ -118,6 +120,7 @@ private: // phonon Phonon::MediaObject *mediaObject; Phonon::VideoWidget *videoWidget; + Phonon::SeekSlider *seekSlider; // loadingWidget VideoAreaWidget *videoAreaWidget; -- 2.39.5