Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Set core audio session category to none
By setting the core audio session to none, miniaudio will not - set a (new) category on the shared audio session - set any (new) options when setting a new category This means that the shared AVAudioSession instance will be respected when audio is played; the developer will have to set up the shared AVAudioSession instance explicitly for their own set up. This does not touch whether the session is made (in)active. This is _probably_ the right way to go about this, rather than overwriting / overriding whatever settings developers had previously set. The side effect of this may be that we will have developers reaching out to us that audio is not playing when the silent switch is toggled on, or audio is not mixing; we should be proactive and update the docs stating that this now respects `AVAudioSession.sharedInstance` settings, and point to Apple's docs for how to set that up. Relevant code from miniaudio: ```c if (pConfig->coreaudio.sessionCategory == ma_ios_session_category_default) { /* I'm going to use trial and error to determine our default session category. First we'll try PlayAndRecord. If that fails we'll try Playback and if that fails we'll try record. If all of these fail we'll just not set the category. */ #if !defined(MA_APPLE_TV) && !defined(MA_APPLE_WATCH) options |= AVAudioSessionCategoryOptionDefaultToSpeaker; #endif if ([pAudioSession setCategory: AVAudioSessionCategoryPlayAndRecord withOptions:options error:nil]) { /* Using PlayAndRecord */ } else if ([pAudioSession setCategory: AVAudioSessionCategoryPlayback withOptions:options error:nil]) { /* Using Playback */ } else if ([pAudioSession setCategory: AVAudioSessionCategoryRecord withOptions:options error:nil]) { /* Using Record */ } else { /* Leave as default? */ } } else { if (pConfig->coreaudio.sessionCategory != ma_ios_session_category_none) { #if defined(__IPHONE_12_0) if (![pAudioSession setCategory: ma_to_AVAudioSessionCategory(pConfig->coreaudio.sessionCategory) withOptions:options error:nil]) { return MA_INVALID_OPERATION; /* Failed to set session category. */ } #else /* Ignore the session category on version 11 and older, but post a warning. */ ma_log_postf(ma_context_get_log(pContext), MA_LOG_LEVEL_WARNING, "Session category only supported in iOS 12 and newer."); #endif } } ``` Diffs= 2be9ddc7e Set core audio session category to none (#7772) Co-authored-by: David Skuza <[email protected]>
- Loading branch information