From fdac8d9c74185e39a46581be8519501251b88fc8 Mon Sep 17 00:00:00 2001 From: Yoann Lopes Date: Thu, 3 Sep 2015 18:42:52 +0200 Subject: AVFoundation: correctly unload current media. When loading a new media, we should unload the previous media. This makes sure all properties set right after loading a new media (e.g. position, volume) are correctly set on the new AVPlayer and not on the old one. Change-Id: I4cd71b785ccdb4cd0772cedffc3c25665f402776 Reviewed-by: Christian Stromme --- .../mediaplayer/avfmediaplayersession.mm | 45 +++++++--------------- 1 file changed, 14 insertions(+), 31 deletions(-) (limited to 'src/plugins/avfoundation') diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm index 1184451ad..c27601936 100644 --- a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm +++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm @@ -121,19 +121,28 @@ static void *AVFMediaPlayerSessionObserverCurrentItemObservationContext = &AVFMe - (void) unloadMedia { - if (m_player) - [m_player setRate:0.0]; if (m_playerItem) { [m_playerItem removeObserver:self forKeyPath:AVF_STATUS_KEY]; [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification - object:m_playerItem]; + object:m_playerItem]; [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemTimeJumpedNotification object:m_playerItem]; m_playerItem = 0; } + if (m_player) { + [m_player setRate:0.0]; + [m_player removeObserver:self forKeyPath:AVF_CURRENT_ITEM_KEY]; + [m_player removeObserver:self forKeyPath:AVF_RATE_KEY]; + [m_player release]; + m_player = 0; + } + if (m_playerLayer) { + [m_playerLayer release]; + m_playerLayer = 0; + } } - (void) prepareToPlayAsset:(AVURLAsset *)asset @@ -203,21 +212,6 @@ static void *AVFMediaPlayerSessionObserverCurrentItemObservationContext = &AVFMe name:AVPlayerItemTimeJumpedNotification object:m_playerItem]; - - //Clean up old player if we have one - if (m_player) { - [m_player setRate:0.0]; - [m_player removeObserver:self forKeyPath:AVF_CURRENT_ITEM_KEY]; - [m_player removeObserver:self forKeyPath:AVF_RATE_KEY]; - [m_player release]; - m_player = 0; - - if (m_playerLayer) { - [m_playerLayer release]; - m_playerLayer = 0; //Will have been released - } - } - //Get a new AVPlayer initialized to play the specified player item. m_player = [AVPlayer playerWithPlayerItem:m_playerItem]; [m_player retain]; @@ -354,18 +348,6 @@ static void *AVFMediaPlayerSessionObserverCurrentItemObservationContext = &AVFMe #endif [self unloadMedia]; - if (m_player) { - [m_player removeObserver:self forKeyPath:AVF_CURRENT_ITEM_KEY]; - [m_player removeObserver:self forKeyPath:AVF_RATE_KEY]; - [m_player release]; - m_player = 0; - } - - if (m_playerLayer) { - [m_playerLayer release]; - m_playerLayer = 0; - } - if (m_URL) { [m_URL release]; } @@ -464,6 +446,8 @@ void AVFMediaPlayerSession::setMedia(const QMediaContent &content, QIODevice *st qDebug() << Q_FUNC_INFO << content.canonicalUrl(); #endif + [(AVFMediaPlayerSessionObserver*)m_observer unloadMedia]; + m_resources = content; m_mediaStream = stream; @@ -475,7 +459,6 @@ void AVFMediaPlayerSession::setMedia(const QMediaContent &content, QIODevice *st QMediaPlayer::MediaStatus oldMediaStatus = m_mediaStatus; if (content.isNull() || content.canonicalUrl().isEmpty()) { - [(AVFMediaPlayerSessionObserver*)m_observer unloadMedia]; m_mediaStatus = QMediaPlayer::NoMedia; if (m_state != QMediaPlayer::StoppedState) Q_EMIT stateChanged(m_state = QMediaPlayer::StoppedState); -- cgit v1.2.3