AVFoundation: fix playback rate.

Calling play on the AVPlayer internally resets the playback rate, which
means any playback rate set before calling play was ignored.
We now always call setRate to start playback to avoid resetting the
rate with play.
Aslo fixed the playbackRateChanged() signal that was never emitted.

Task-number: QTBUG-45570
Change-Id: I3a77e1db31c57f1e3491287bdf977731b9d73509
Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
This commit is contained in:
Yoann Lopes
2015-09-03 15:48:37 +02:00
parent 29ce8886b3
commit 95fa47f747
3 changed files with 13 additions and 8 deletions

View File

@@ -63,6 +63,8 @@ void AVFMediaPlayerControl::setSession(AVFMediaPlayerSession *session)
connect(m_session, SIGNAL(audioAvailableChanged(bool)), this, SIGNAL(audioAvailableChanged(bool)));
connect(m_session, SIGNAL(videoAvailableChanged(bool)), this, SIGNAL(videoAvailableChanged(bool)));
connect(m_session, SIGNAL(error(int,QString)), this, SIGNAL(error(int,QString)));
connect(m_session, &AVFMediaPlayerSession::playbackRateChanged,
this, &AVFMediaPlayerControl::playbackRateChanged);
}
QMediaPlayer::State AVFMediaPlayerControl::state() const

View File

@@ -106,6 +106,7 @@ Q_SIGNALS:
void mutedChanged(bool muted);
void audioAvailableChanged(bool audioAvailable);
void videoAvailableChanged(bool videoAvailable);
void playbackRateChanged(qreal rate);
void error(int error, const QString &errorString);
private:

View File

@@ -602,10 +602,10 @@ void AVFMediaPlayerSession::setPlaybackRate(qreal rate)
m_rate = rate;
AVPlayer *player = [(AVFMediaPlayerSessionObserver*)m_observer player];
if (player != 0 && m_state == QMediaPlayer::PlayingState) {
if (player && m_state == QMediaPlayer::PlayingState)
[player setRate:m_rate];
}
Q_EMIT playbackRateChanged(m_rate);
}
void AVFMediaPlayerSession::setPosition(qint64 pos)
@@ -655,8 +655,10 @@ void AVFMediaPlayerSession::play()
processLoadStateChange();
}
if (m_mediaStatus == QMediaPlayer::LoadedMedia || m_mediaStatus == QMediaPlayer::BufferedMedia)
[[(AVFMediaPlayerSessionObserver*)m_observer player] play];
if (m_mediaStatus == QMediaPlayer::LoadedMedia || m_mediaStatus == QMediaPlayer::BufferedMedia) {
// Setting the rate starts playback
[[(AVFMediaPlayerSessionObserver*)m_observer player] setRate:m_rate];
}
//processLoadStateChange();
Q_EMIT stateChanged(m_state);
@@ -697,8 +699,8 @@ void AVFMediaPlayerSession::stop()
return;
m_state = QMediaPlayer::StoppedState;
m_rate = 0.0f;
[[(AVFMediaPlayerSessionObserver*)m_observer player] setRate:m_rate];
// AVPlayer doesn't have stop(), only pause() and play().
[[(AVFMediaPlayerSessionObserver*)m_observer player] pause];
setPosition(0);
if (m_videoOutput) {
@@ -821,8 +823,8 @@ void AVFMediaPlayerSession::processLoadStateChange()
newStatus = isPlaying ? QMediaPlayer::BufferedMedia : QMediaPlayer::LoadedMedia;
if (m_state == QMediaPlayer::PlayingState && [(AVFMediaPlayerSessionObserver*)m_observer player]) {
// Setting the rate is enough to start playback, no need to call play()
[[(AVFMediaPlayerSessionObserver*)m_observer player] setRate:m_rate];
[[(AVFMediaPlayerSessionObserver*)m_observer player] play];
}
}