AVFoundation: fix mediaStatus and state changes
When both state and mediaStatus are updated at the same time, make sure both variables are updated before emitting the corresponding signals. Also, always emit mediaStatusChanged() signals before stateChanged() to make sure mediaStatus changes are not cancelled by some action resulting from a state change. Task-number: QTBUG-49578 Change-Id: I0caea8261120595227834dbac7fed286d125bcab Reviewed-by: Christian Stromme <christian.stromme@qt.io>
This commit is contained in:
@@ -458,15 +458,19 @@ void AVFMediaPlayerSession::setMedia(const QMediaContent &content, QIODevice *st
|
|||||||
m_requestedPosition = -1;
|
m_requestedPosition = -1;
|
||||||
Q_EMIT positionChanged(position());
|
Q_EMIT positionChanged(position());
|
||||||
|
|
||||||
QMediaPlayer::MediaStatus oldMediaStatus = m_mediaStatus;
|
const QMediaPlayer::MediaStatus oldMediaStatus = m_mediaStatus;
|
||||||
|
const QMediaPlayer::State oldState = m_state;
|
||||||
|
|
||||||
if (content.isNull() || content.canonicalUrl().isEmpty()) {
|
if (content.isNull() || content.canonicalUrl().isEmpty()) {
|
||||||
m_mediaStatus = QMediaPlayer::NoMedia;
|
m_mediaStatus = QMediaPlayer::NoMedia;
|
||||||
if (m_state != QMediaPlayer::StoppedState)
|
m_state = QMediaPlayer::StoppedState;
|
||||||
Q_EMIT stateChanged(m_state = QMediaPlayer::StoppedState);
|
|
||||||
|
|
||||||
if (m_mediaStatus != oldMediaStatus)
|
if (m_mediaStatus != oldMediaStatus)
|
||||||
Q_EMIT mediaStatusChanged(m_mediaStatus);
|
Q_EMIT mediaStatusChanged(m_mediaStatus);
|
||||||
|
|
||||||
|
if (m_state != oldState)
|
||||||
|
Q_EMIT stateChanged(m_state);
|
||||||
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
@@ -777,14 +781,15 @@ void AVFMediaPlayerSession::processEOS()
|
|||||||
#endif
|
#endif
|
||||||
Q_EMIT positionChanged(position());
|
Q_EMIT positionChanged(position());
|
||||||
m_mediaStatus = QMediaPlayer::EndOfMedia;
|
m_mediaStatus = QMediaPlayer::EndOfMedia;
|
||||||
|
m_state = QMediaPlayer::StoppedState;
|
||||||
|
|
||||||
// At this point, frames should not be rendered anymore.
|
// At this point, frames should not be rendered anymore.
|
||||||
// Clear the output layer to make sure of that.
|
// Clear the output layer to make sure of that.
|
||||||
if (m_videoOutput)
|
if (m_videoOutput)
|
||||||
m_videoOutput->setLayer(0);
|
m_videoOutput->setLayer(0);
|
||||||
|
|
||||||
Q_EMIT stateChanged(m_state = QMediaPlayer::StoppedState);
|
|
||||||
Q_EMIT mediaStatusChanged(m_mediaStatus);
|
Q_EMIT mediaStatusChanged(m_mediaStatus);
|
||||||
|
Q_EMIT stateChanged(m_state);
|
||||||
}
|
}
|
||||||
|
|
||||||
void AVFMediaPlayerSession::processLoadStateChange()
|
void AVFMediaPlayerSession::processLoadStateChange()
|
||||||
@@ -864,7 +869,11 @@ void AVFMediaPlayerSession::processMediaLoadError()
|
|||||||
m_requestedPosition = -1;
|
m_requestedPosition = -1;
|
||||||
Q_EMIT positionChanged(position());
|
Q_EMIT positionChanged(position());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_mediaStatus = QMediaPlayer::InvalidMedia;
|
||||||
|
m_state = QMediaPlayer::StoppedState;
|
||||||
|
|
||||||
Q_EMIT error(QMediaPlayer::FormatError, tr("Failed to load media"));
|
Q_EMIT error(QMediaPlayer::FormatError, tr("Failed to load media"));
|
||||||
Q_EMIT mediaStatusChanged(m_mediaStatus = QMediaPlayer::InvalidMedia);
|
Q_EMIT mediaStatusChanged(m_mediaStatus);
|
||||||
Q_EMIT stateChanged(m_state = QMediaPlayer::StoppedState);
|
Q_EMIT stateChanged(m_state);
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user