summaryrefslogtreecommitdiffstats
path: root/src/plugins/avfoundation/mediaplayer
diff options
context:
space:
mode:
authorYoann Lopes <yoann.lopes@theqtcompany.com>2015-09-03 18:42:52 +0200
committerYoann Lopes <yoann.lopes@theqtcompany.com>2015-09-15 09:10:16 +0000
commitfdac8d9c74185e39a46581be8519501251b88fc8 (patch)
treed33d61fdebb5bcb086ad3bbe7ac3e2db9db012ed /src/plugins/avfoundation/mediaplayer
parentbede0a838ddafadafc400f20c00a687e753ea638 (diff)
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 <christian.stromme@theqtcompany.com>
Diffstat (limited to 'src/plugins/avfoundation/mediaplayer')
-rw-r--r--src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm45
1 files changed, 14 insertions, 31 deletions
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);