Android: fixed media player buffering logic.
When the media is ready, the status should always transition to LoadedMedia and then immediately to BufferingMedia or BufferedMedia. Also, when the duration is queried before the media is ready but already buffering, it should always return 0 to avoid errors from the Android media player. Task-number: QTBUG-32635 Change-Id: Ibcb9c23b4f64c4f9a1a8e0ef81989ae78cfb19ef Reviewed-by: Christian Stromme <christian.stromme@digia.com>
This commit is contained in:
committed by
The Qt Project
parent
c86d14a380
commit
4585518d52
@@ -191,8 +191,8 @@ public class QtAndroidMediaPlayer extends MediaPlayer
|
||||
@Override
|
||||
public void onPrepared(final MediaPlayer mp)
|
||||
{
|
||||
onMediaPlayerInfoNative(MEDIA_PLAYER_DURATION, getDuration(), mID);
|
||||
onMediaPlayerInfoNative(MEDIA_PLAYER_READY, 0, mID);
|
||||
onMediaPlayerInfoNative(MEDIA_PLAYER_DURATION, getDuration(), mID);
|
||||
mPreparing = false;
|
||||
}
|
||||
|
||||
|
||||
@@ -98,8 +98,9 @@ QMediaPlayer::MediaStatus QAndroidMediaPlayerControl::mediaStatus() const
|
||||
qint64 QAndroidMediaPlayerControl::duration() const
|
||||
{
|
||||
return (mCurrentMediaStatus == QMediaPlayer::InvalidMedia
|
||||
|| mCurrentMediaStatus == QMediaPlayer::NoMedia) ? 0
|
||||
: mMediaPlayer->getDuration();
|
||||
|| mCurrentMediaStatus == QMediaPlayer::NoMedia
|
||||
|| !mMediaPlayerReady) ? 0
|
||||
: mMediaPlayer->getDuration();
|
||||
}
|
||||
|
||||
qint64 QAndroidMediaPlayerControl::position() const
|
||||
@@ -330,14 +331,12 @@ void QAndroidMediaPlayerControl::onMediaPlayerInfo(qint32 what, qint32 extra)
|
||||
setState(QMediaPlayer::StoppedState);
|
||||
break;
|
||||
case JMediaPlayer::MEDIA_PLAYER_READY:
|
||||
setMediaStatus(QMediaPlayer::LoadedMedia);
|
||||
if (mBuffering) {
|
||||
setMediaStatus(mBufferPercent == 100 ? QMediaPlayer::BufferedMedia
|
||||
: QMediaPlayer::BufferingMedia);
|
||||
} else {
|
||||
setMediaStatus(QMediaPlayer::LoadedMedia);
|
||||
mBufferPercent = 100;
|
||||
Q_EMIT bufferStatusChanged(mBufferPercent);
|
||||
updateAvailablePlaybackRanges();
|
||||
onBufferChanged(100);
|
||||
}
|
||||
setAudioAvailable(true);
|
||||
mMediaPlayerReady = true;
|
||||
@@ -402,7 +401,7 @@ void QAndroidMediaPlayerControl::onError(qint32 what, qint32 extra)
|
||||
|
||||
void QAndroidMediaPlayerControl::onBufferChanged(qint32 percent)
|
||||
{
|
||||
mBuffering = true;
|
||||
mBuffering = percent != 100;
|
||||
mBufferPercent = percent;
|
||||
Q_EMIT bufferStatusChanged(mBufferPercent);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user