diff options
author | Lars Sutterud <lars.sutterud@qt.io> | 2023-11-30 12:51:17 +0100 |
---|---|---|
committer | Qt Cherry-pick Bot <cherrypick_bot@qt-project.org> | 2023-12-22 22:07:12 +0000 |
commit | 9010e3505aa9c39357ecfa5eca9ac3642c1c0b61 (patch) | |
tree | e1afa370d06eaf095fb1abd4d5d4ed045432c1b6 | |
parent | e10501f443ac6943c50f1b88712b09554ed38703 (diff) |
QFFmpegMediaPlayer: Fix stop() not resetting position if EndOfMedia
If QFFmpegMediaPlayer::stop() was called after playing a media file all
the way to the end, the playback position of the would not be reset.
In that scenario, a subsequent call to play() would just reset the
position to 0 instead of starting playback from the beginning as
expected.
Solution:
- Call m_playbackEngine->seek(0) in stop()
- Write new test that covers the above scenario
Fixes: QTBUG-118127
Pick-to: 6.5
Change-Id: Ibcb313721099c3e53fd6b1b1d52aad712a0c8eb0
Reviewed-by: Artem Dyomin <artem.dyomin@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Jøger Hansegård <joger.hansegard@qt.io>
(cherry picked from commit ad783bb7099fbbc98cf1a27ea8a5910604fc7596)
Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
(cherry picked from commit c36e6fec8e177761a62b850ba368a35ce68d95fd)
-rw-r--r-- | src/plugins/multimedia/ffmpeg/qffmpegmediaplayer.cpp | 1 | ||||
-rw-r--r-- | tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp | 22 |
2 files changed, 23 insertions, 0 deletions
diff --git a/src/plugins/multimedia/ffmpeg/qffmpegmediaplayer.cpp b/src/plugins/multimedia/ffmpeg/qffmpegmediaplayer.cpp index 335312199..fe8e83a97 100644 --- a/src/plugins/multimedia/ffmpeg/qffmpegmediaplayer.cpp +++ b/src/plugins/multimedia/ffmpeg/qffmpegmediaplayer.cpp @@ -314,6 +314,7 @@ void QFFmpegMediaPlayer::stop() m_playbackEngine->stop(); m_positionUpdateTimer.stop(); + m_playbackEngine->seek(0); positionChanged(0); stateChanged(QMediaPlayer::StoppedState); mediaStatusChanged(QMediaPlayer::LoadedMedia); diff --git a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp index 9489fe26c..9e02dfea5 100644 --- a/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp +++ b/tests/auto/integration/qmediaplayerbackend/tst_qmediaplayerbackend.cpp @@ -117,6 +117,7 @@ private slots: void play_waitsForLastFrameEnd_whenPlayingVideoWithLongFrames(); void stop_entersStoppedState_whenPlayerWasPaused(); + void stop_setsPositionToZero_afterPlayingToEndOfMedia(); void playbackRate_returnsOne_byDefault(); void setPlaybackRate_changesPlaybackRateAndEmitsSignal_data(); @@ -1133,6 +1134,27 @@ void tst_QMediaPlayerBackend::stop_entersStoppedState_whenPlayerWasPaused() QVERIFY(m_fixture->player.duration() > 0); } +void tst_QMediaPlayerBackend::stop_setsPositionToZero_afterPlayingToEndOfMedia() +{ + // Arrange + m_fixture->player.setSource(*m_localVideoFile3ColorsWithSound); + m_fixture->player.play(); + QTRY_COMPARE(m_fixture->player.mediaStatus(), QMediaPlayer::EndOfMedia); + QCOMPARE(m_fixture->player.playbackState(), QMediaPlayer::StoppedState); + + // Act + m_fixture->player.stop(); + + // Assert + QCOMPARE(m_fixture->player.position(), qint64(0)); + QTRY_COMPARE(m_fixture->player.mediaStatus(), QMediaPlayer::LoadedMedia); + QCOMPARE(m_fixture->player.playbackState(), QMediaPlayer::StoppedState); + + m_fixture->player.play(); + QVERIFY(m_fixture->surface.waitForFrame().isValid()); +} + + void tst_QMediaPlayerBackend::playbackRate_returnsOne_byDefault() { QCOMPARE_EQ(m_fixture->player.playbackRate(), static_cast<qreal>(1.0f)); |