Fix playing a playlist containing an invalid media as first item

When a playlist contains an invalid media, QMediaPlayer normally
continues to the next media. If an invalid media was first in the list,
the backend would never go into PlayingState, which would then cause
the media player to never start the next item in the list (thinking
it's stopped).
We now always transition to PlayingState when starting playback of a
playlist, regardless of the backend going into that state or not.

Change-Id: I4227f937e7a619afbd8adbe2fccedfa5d43ad89a
Reviewed-by: Christian Stromme <christian.stromme@qt.io>
This commit is contained in:
Yoann Lopes
2016-08-01 16:14:46 +02:00
parent 124987e4bc
commit cf439602fd

View File

@@ -853,17 +853,19 @@ void QMediaPlayer::play()
} }
//if playlist control is available, the service should advance itself //if playlist control is available, the service should advance itself
if (d->rootMedia.playlist() && d->rootMedia.playlist()->currentIndex() == -1 && !d->rootMedia.playlist()->isEmpty()) { if (d->rootMedia.playlist() && !d->rootMedia.playlist()->isEmpty()) {
// switch to playing state // switch to playing state
if (d->state != QMediaPlayer::PlayingState) if (d->state != QMediaPlayer::PlayingState)
d->_q_stateChanged(QMediaPlayer::PlayingState); d->_q_stateChanged(QMediaPlayer::PlayingState);
if (d->playlist != d->rootMedia.playlist()) if (d->rootMedia.playlist()->currentIndex() == -1) {
d->setPlaylist(d->rootMedia.playlist()); if (d->playlist != d->rootMedia.playlist())
Q_ASSERT(d->playlist == d->rootMedia.playlist()); d->setPlaylist(d->rootMedia.playlist());
emit currentMediaChanged(d->rootMedia); Q_ASSERT(d->playlist == d->rootMedia.playlist());
d->playlist->setCurrentIndex(0);
emit currentMediaChanged(d->rootMedia);
d->playlist->setCurrentIndex(0);
}
} }
// Reset error conditions // Reset error conditions