diff options
author | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-09-03 17:02:26 +0200 |
---|---|---|
committer | Yoann Lopes <yoann.lopes@theqtcompany.com> | 2015-09-15 09:09:42 +0000 |
commit | 6a6a69b7d8343a3cdd9daff60b9288eb361148c9 (patch) | |
tree | e5ef988de6805fd82c6940d8cc2b345ff4eb30b6 /src | |
parent | 95fa47f7472ac9bcb99df98bcd02c9a1907b6f3a (diff) | |
download | qtmultimedia-6a6a69b7d8343a3cdd9daff60b9288eb361148c9.tar.gz |
AVFoundation: fix initial volume.
The volume level set before loading a media was never actually set on
AVPlayer.
Regression introduced by 4e07ff99 on OSX.
Task-number: QTBUG-48154
Change-Id: I599e3d55b35d7196aebc4753a367a29049f99d33
Reviewed-by: Christian Stromme <christian.stromme@theqtcompany.com>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/avfoundation/mediaplayer/avfmediaplayersession.h | 3 | ||||
-rw-r--r-- | src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm | 47 |
2 files changed, 28 insertions, 22 deletions
diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.h b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.h index decab1b37..1e675c029 100644 --- a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.h +++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.h @@ -80,6 +80,8 @@ public: qreal playbackRate() const; + inline bool isVolumeSupported() const { return m_volumeSupported; } + public Q_SLOTS: void setPlaybackRate(qreal rate); @@ -159,6 +161,7 @@ private: QMediaContent m_resources; ResourceHandler m_resourceHandler; + const bool m_volumeSupported; bool m_muted; bool m_tryingAsync; int m_volume; diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm index c0e813219..d9d705c68 100644 --- a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm +++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm @@ -222,11 +222,11 @@ static void *AVFMediaPlayerSessionObserverCurrentItemObservationContext = &AVFMe m_player = [AVPlayer playerWithPlayerItem:m_playerItem]; [m_player retain]; -#if defined(Q_OS_OSX) //Set the initial volume on new player object - if (self.session) - m_player.volume = m_session->volume() / 100.0f; -#endif + if (self.session && self.session->isVolumeSupported()) { + [m_player setVolume:m_session->volume() / 100.0f]; + [m_player setMuted:m_session->isMuted()]; + } //Create a new player layer if we don't have one already if (!m_playerLayer) @@ -382,6 +382,11 @@ AVFMediaPlayerSession::AVFMediaPlayerSession(AVFMediaPlayerService *service, QOb , m_state(QMediaPlayer::StoppedState) , m_mediaStatus(QMediaPlayer::NoMedia) , m_mediaStream(0) +#ifdef Q_OS_IOS + , m_volumeSupported(QSysInfo::MacintoshVersion >= QSysInfo::MV_IOS_7_0) +#else + , m_volumeSupported(true) +#endif , m_muted(false) , m_tryingAsync(false) , m_volume(100) @@ -718,21 +723,20 @@ void AVFMediaPlayerSession::setVolume(int volume) qDebug() << Q_FUNC_INFO << volume; #endif - if (m_volume == volume) - return; - - AVPlayer *player = [(AVFMediaPlayerSessionObserver*)m_observer player]; - if (!player) - return; - - if (![player respondsToSelector:@selector(setVolume:)]) { + if (!m_volumeSupported) { qWarning("%s not implemented, requires iOS 7 or later", Q_FUNC_INFO); return; } - [player setVolume:volume / 100.0f]; + if (m_volume == volume) + return; + m_volume = volume; + AVPlayer *player = [(AVFMediaPlayerSessionObserver*)m_observer player]; + if (player) + [player setVolume:volume / 100.0f]; + Q_EMIT volumeChanged(m_volume); } @@ -741,22 +745,21 @@ void AVFMediaPlayerSession::setMuted(bool muted) #ifdef QT_DEBUG_AVF qDebug() << Q_FUNC_INFO << muted; #endif - if (m_muted == muted) - return; - - AVPlayer *player = [(AVFMediaPlayerSessionObserver*)m_observer player]; - if (!player) - return; - // iOS: setMuted exists since iOS 7.0, thus check if it exists - if (![player respondsToSelector:@selector(setMuted:)]) { + if (!m_volumeSupported) { qWarning("%s not implemented, requires iOS 7 or later", Q_FUNC_INFO); return; } - [player setMuted:muted]; + if (m_muted == muted) + return; + m_muted = muted; + AVPlayer *player = [(AVFMediaPlayerSessionObserver*)m_observer player]; + if (player) + [player setMuted:muted]; + Q_EMIT mutedChanged(muted); } |