From 4e07ff99f6ed49da3853c3f34cce393820105f1c Mon Sep 17 00:00:00 2001 From: Frank Osterfeld Date: Tue, 24 Feb 2015 22:40:55 +0100 Subject: [PATCH] ios: Enable volume and mute functionality AVPlayer::setVolume and setMute also exist on iOS, so no need to ifdef them to be OS X-only. As they require iOS 7.0, add runtime checks to ensure that the methods exist. Task-number: QTBUG-39240 Change-Id: I10810705cef8e5d8c18e4c79a15fa06425ea57f9 Reviewed-by: Yoann Lopes Reviewed-by: James Turner --- .../mediaplayer/avfmediaplayersession.mm | 30 +++++++++++++++------- 1 file changed, 21 insertions(+), 9 deletions(-) diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm index 8b87be8..005c00a 100644 --- a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm +++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm @@ -719,14 +719,17 @@ void AVFMediaPlayerSession::setVolume(int volume) if (m_volume == volume) return; - m_volume = volume; - -#if defined(Q_OS_OSX) AVPlayer *player = [(AVFMediaPlayerSessionObserver*)m_observer player]; - if (player) { - [[(AVFMediaPlayerSessionObserver*)m_observer player] setVolume:m_volume / 100.0f]; + if (!player) + return; + + if (![player respondsToSelector:@selector(setVolume:)]) { + qWarning("%s not implemented, requires iOS 7 or later", Q_FUNC_INFO); + return; } -#endif + + [player setVolume:m_volume / 100.0f]; + m_volume = volume; Q_EMIT volumeChanged(m_volume); } @@ -739,10 +742,19 @@ void AVFMediaPlayerSession::setMuted(bool muted) 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:)]) { + qWarning("%s not implemented, requires iOS 7 or later", Q_FUNC_INFO); + return; + } + + [player setMuted:m_muted]; m_muted = muted; -#if defined(Q_OS_OSX) - [[(AVFMediaPlayerSessionObserver*)m_observer player] setMuted:m_muted]; -#endif + Q_EMIT mutedChanged(muted); } -- 2.7.4