From ab57d0efd91542aa542e3204bc01f8c894181efa Mon Sep 17 00:00:00 2001 From: Val Doroshchuk Date: Thu, 30 Apr 2020 11:37:17 +0200 Subject: AVF: Set playback audio session category while playing MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Since when the application is active and then moved into the background then audio can be played fine. But if the application is already in the background then it will not play the audio. Decided to set AVAudioSessionCategoryPlayback with AVAudioSessionCategoryOptionMixWithOthers to audio session, which leads to restart playing from the background. Fixes: QTBUG-69949 Change-Id: I18fb4904b0810b7dfb63585278edbb8ee2f02d05 Reviewed-by: Tor Arne Vestbø --- src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm index 61a78ac03..95121f58a 100644 --- a/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm +++ b/src/plugins/avfoundation/mediaplayer/avfmediaplayersession.mm @@ -176,6 +176,9 @@ static void *AVFMediaPlayerSessionObserverCurrentItemDurationObservationContext [m_playerLayer release]; m_playerLayer = 0; } +#if defined(Q_OS_IOS) + [[AVAudioSession sharedInstance] setActive:NO error:nil]; +#endif } - (void) prepareToPlayAsset:(AVURLAsset *)asset @@ -288,7 +291,10 @@ static void *AVFMediaPlayerSessionObserverCurrentItemDurationObservationContext forKeyPath:AVF_CURRENT_ITEM_DURATION_KEY options:0 context:AVFMediaPlayerSessionObserverCurrentItemDurationObservationContext]; - +#if defined(Q_OS_IOS) + [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionMixWithOthers error:nil]; + [[AVAudioSession sharedInstance] setActive:YES error:nil]; +#endif } -(void) assetFailedToPrepareForPlayback:(NSError *)error -- cgit v1.2.3