版本
-
-
-
-
Samples
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
In order for your audio app to easily and correctly manage audio session using the Wwise SDK, a certain number of simple steps are required. Wwise handles a lot of the iOS audio session complexities behind the scene in order to let the user focus on the app essentials. All audio interruption, source change mechanic are already taken care of internally by Wwise and their associated callbacks are totally optional for the end user. Suspending and resuming the sound engine in those cases is also handled by the SDK.
The Integration Demo offers an excellent starting point to learn how to configure and initialize the different audio session parameters as well as the registration of the audio interrupt callback and audio route change. All these steps can be found in IntegrationDemoAppDelegate.mm
source file.
To configure the app audio session and the different available callbacks use:
struct AkInitSettings
struct AkPlatformInitSettings
Use struct AkPlatformInitSettings::AkAudioSessionProperties
member to set eCategory, eCategoryOptions, and eMode to the desired audio session category with optional override options and modes for the app.
|
Note:
|
|
Note:
|
Here are the simple steps required by any Wwise SDK user app in order to easily create a working audio app that is fully iOS audio session compliant:
struct AkPlatformInitSettings.audioSession.eCategory
with desired value.struct AkPlatformInitSettings.audioSession.eCategoryOptions
with desired value (optional).struct AkPlatformInitSettings.audioCallbacks.interruptionCallback
to the user defined callback method.AkAudioSourceChangeCallbackFunc
type, which is of the form AKRESULT
callBackName(bool, void*).true
, so if a complete audio engine disabling is required by your app, it can be done in the user interruption callback. struct AkInitSettings.sourceChangeCallback
to the user defined callback method.AkAudioSourceChangeCallbackFunc
type which is of the form AKRESULT
callBackName(bool, void*).AVAudioSessionRouteChangeNotification
and provide a selector for it (callback)AK::SoundEngine::Suspend(false)
in your app delegate - (void)applicationWillResignActive:(UIApplication *)application method.AK::SoundEngine::WakeupFromSuspend()
in your app delegate - (void)applicationDidBecomeActive:(UIApplication *)application method.AkAudioSessionCategoryPlayAndRecord
category along with the modified app info plist as explained above.
|
Note: Refer to the iOS Integration Demo IntegrationDemoAppDelegate.mm source code for examples on all the above mentioned steps. |
|
Caution: Make sure all the above steps (except the foreground/background switch handling) are done before initializing the sound engine with AK::SoundEngine::Init( &in_initSettings, &in_platformInitSettings ) . |
App state switch handling is usually done through the UIApplicationDelegate
protocol that any app should implement. Any app can be in any of five states as presented in the Apple documentation:
When an app is switched from foreground to background either using the Home button or by the system when answering a phone call for example, the following delegate methods will be called in this order:
(void)applicationWillResignActive:(UIApplication *)application
(void)applicationDidEnterBackground:(UIApplication *)application
Reciprocally, when an app transitions from background to foreground using the Home buton or when terminating a phone call that previously interrupted your app, the following delegate methods get called in this order:
(void)applicationWillEnterForeground:(UIApplication *)application
(void)applicationDidBecomeActive:(UIApplication *)application
If an app has no specific background operations to do, it is transitioned to suspended state shortly after being in the background state. It can even be terminated without any notice from iOS if, for example, memory runs low on the sytem.
Because those delegates are tied to a running application, Wwise runtime is not aware of them and should not be in any case. If your app does not require playing or recording sound in the background, it is then strongly suggested to suspend the sound engine before leaving the active state in order to limit unncessary CPU processing and to prevent your app from crashing due to system audio ressource access limitations. Similarly, when your app is about to be moved from the background into the foreground active state, the sound engine must be resumed in order for your app to be able to resume its audio operations. These suspend/resume operations must, therefore, be done in your application (void)applicationWillResignActive:(UIApplication *)application
and (void)applicationDidEnterBackground:(UIApplication *)application
delegate methods respectively.
|
Note: Only audio session category AkAudioSessionCategoryPlayAndRecord allows for audio to be played and/or recorded in an app background state. If this behavior is required, the app info plist must also be modified in Xcode to add the 'Required background modes' key with the 'App plays audio or streams audio/video using Airplay' value. |
To have a better understanding of the overall callflow that happens in diverse audio session sharing scenarios, we present some cases here to illustrate how inter-app audio is handled using Wwise and the iOS audio session.
applicationWillResignActive()
gets called and its up to the user app to suspend the AK::SoundEngine::Suspend(bool in_bRenderAnyway)
call.in_bRenderAnyway
set to false
.applicationDidBecomeActive()
gets called and the user should resume the sound engine processing using an AK::SoundEngine::WakeupFromSuspend()
call.applicationWillResignActive()
gets called and its up to the user app to suspend the Wwise sound engine using the AK::SoundEngine::Suspend(bool in_bRenderAnyway)
call.applicationDidBecomeActive()
gets called and the user should resume the sound engine processing using a AK::SoundEngine::WakeupFromSuspend()
call.Ambient
or PlayAndRecord
with the 'mixable' option), the source change notification in the Wwise SDK will mute the background music bus as described in Audio Session categories and options.applicationWillResignActive()
gets called and its up to the user app to suspend the Wwise sound engine using a AK::SoundEngine::Suspend(bool in_bRenderAnyway)
call. AkAudioSessionCategoryAmbient
category:AkAudioSessionCategorySoloAmbient
category:AkAudioSessionCategoryPlayAndRecord
category:AkAudioSessionCategoryAmbient
category.