[phonon-vlc] src: fix transit to next track & abouttofinish madness
Harald Sitter
sitter at kde.org
Tue Dec 11 12:07:34 GMT 2012
Git commit 1345fc3deae1be28520dbeefc4f97452fef64a5d by Harald Sitter.
Committed on 11/12/2012 at 13:07.
Pushed by sitter into branch 'master'.
fix transit to next track & abouttofinish madness
- rename checkgaplesswaiting to hasnexttrack
- when the player emits endedstate and we have a next track -> continue,
otherwise emit abouttofinish and stop
- don't discard state changes when we have pending tracks
- when setNextSource is called when in stopped state, make sure we
go to the source right away as that would be caused by a timing issue
WRT queuing of signals, so libphonon wanted us to play that song before
the other finished, but due to timing we only get the song after we are
stopped
before putting this into 0.6 I'd like to have some statements that this
does not break any existing software! in fact I'd rather not put this in
0.6 at all...
CCMAIL: kde-multimedia at kde.org
REVIEW: 107118
M +19 -16 src/mediaobject.cpp
M +1 -1 src/mediaobject.h
http://commits.kde.org/phonon-vlc/1345fc3deae1be28520dbeefc4f97452fef64a5d
diff --git a/src/mediaobject.cpp b/src/mediaobject.cpp
index 5b5dae2..ad58a50 100644
--- a/src/mediaobject.cpp
+++ b/src/mediaobject.cpp
@@ -411,6 +411,14 @@ void MediaObject::setNextSource(const MediaSource &source)
DEBUG_BLOCK;
debug() << source.url();
m_nextSource = source;
+ // This function is not ever called by the consumer but only libphonon.
+ // Furthermore libphonon only calls this function in its aboutToFinish slot,
+ // iff sources are already in the queue. In case our aboutToFinish was too
+ // late we may already be stopped when the slot gets activated.
+ // Therefore we need to make sure that we move to the next source iff
+ // this function is called when we are in stoppedstate.
+ if (m_state == StoppedState)
+ moveToNext();
}
qint32 MediaObject::prefinishMark() const
@@ -450,14 +458,10 @@ void MediaObject::emitAboutToFinish()
void MediaObject::changeState(Phonon::State newState)
{
DEBUG_BLOCK;
- if (newState == m_state) {
- // State not changed
- return;
- } else if (checkGaplessWaiting()) {
- // This is a no-op, warn that we are....
- debug() << Q_FUNC_INFO << "no-op gapless item awaiting in queue - " << m_nextSource.type() ;
+
+ // State not changed
+ if (newState == m_state)
return;
- }
debug() << m_state << "-->" << newState;
@@ -482,19 +486,14 @@ void MediaObject::changeState(Phonon::State newState)
void MediaObject::moveToNextSource()
{
DEBUG_BLOCK;
- if (m_nextSource.type() == MediaSource::Invalid) {
- // No item is scheduled to be next...
- return;
- }
setSource(m_nextSource);
play();
m_nextSource = MediaSource(QUrl());
}
-inline bool MediaObject::checkGaplessWaiting()
+inline bool MediaObject::hasNextTrack()
{
- DEBUG_BLOCK;
return m_nextSource.type() != MediaSource::Invalid && m_nextSource.type() != MediaSource::Empty;
}
@@ -645,9 +644,13 @@ void MediaObject::updateState(MediaPlayer::State state)
changeState(StoppedState);
break;
case MediaPlayer::EndedState:
- emitAboutToFinish();
- emit finished();
- changeState(StoppedState);
+ if (hasNextTrack())
+ moveToNextSource();
+ else {
+ emitAboutToFinish();
+ emit finished();
+ changeState(StoppedState);
+ }
break;
case MediaPlayer::ErrorState:
debug() << errorString();
diff --git a/src/mediaobject.h b/src/mediaobject.h
index 281cf50..5233da5 100644
--- a/src/mediaobject.h
+++ b/src/mediaobject.h
@@ -277,7 +277,7 @@ private:
*/
void seekInternal(qint64 milliseconds);
- bool checkGaplessWaiting();
+ bool hasNextTrack();
/**
* Changes the current state to buffering and sets the new current file.
More information about the kde-multimedia
mailing list