Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

iOS Background Audio Not Working #51

Closed
jasonpkovalski opened this issue Apr 7, 2022 · 10 comments
Closed

iOS Background Audio Not Working #51

jasonpkovalski opened this issue Apr 7, 2022 · 10 comments

Comments

@jasonpkovalski
Copy link

My understanding is that background audio should work on iOS with the following setup:

  1. Set Suspend At Focus Loss to OFF
    Screen Shot 2022-04-06 at 8 06 17 PM
  2. Set Audio Session Category to Playback
    Screen Shot 2022-04-06 at 8 06 28 PM
  3. Add the background mode capability in Xcode with audio checked
    Screen Shot 2022-04-06 at 8 06 47 PM

I saw a recent issue regarding background audio, and it seems like the above configuration should work. However, whenever I go to the phone's home screen or another app, the audio pauses, and it resumes when I return to the app.

Am I missing anything?

@alessandrofama
Copy link
Owner

I think we are not setting the Audio Session Category Options correctly due to a oversight in the cpp codebase, setting it to the Audio Session Category value, ups! Maybe fixing this will solve your problem (don't have an iOS device right now, so I hope it will!). I will provide you updated libs later.

@jasonpkovalski
Copy link
Author

Great, I will look out for the updated libs here. I appreciate the prompt responses!

@alessandrofama
Copy link
Owner

alessandrofama commented Apr 7, 2022

The iOS libs from the latest push: https://github.com/alessandrofama/wwise-godot-integration/suites/5976781777/artifacts/205723631

Not sure it will actually fix this, after researching a bit I've found this documentation entry: (https://www.audiokinetic.com/library/edge/?source=SDK&id=pg_ios_working_with_audio_session_with_wwise.html):

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.

Does it actually work with AkAudioSessionCategoryPlayAndRecord for you?

Checking my private Wwise groups I've also found this post mentioning Audiokinetic confirming it's not possible (in contrast with the docs entry above):

image

Might be just an Unity issue there... don't know.

I will look for an updated answer to this issue and let you know if I got something. Sorry for the trouble!

@jasonpkovalski
Copy link
Author

@alessandrofama Just tried with the libs you provided with Audio Session Category set to both Playback and Play And Record. Unfortunately, both are not working as expected still. However, interestingly, when I pull the lock screen down and then exit the app, background audio now plays. It does not play when I go to the home screen or another app directly from the app though 🤔

@jasonpkovalski
Copy link
Author

jasonpkovalski commented Apr 8, 2022

Not sure if this is helpful at all, but I do notice a couple of errors logged in Xcode when running the app:

2022-04-07 22:02:10.119642-0400 [37033:3115785] ERROR: AudioOutputUnitStart failed, code: -50
2022-04-07 22:02:10.119684-0400 [37033:3115785]    at: start (drivers/coreaudio/audio_driver_coreaudio.cpp:249) - AudioOutputUnitStart failed, code: -50
2022-04-07 22:02:10.122286-0400 [37033:3115785] Godot Engine v3.4.2.stable.official.45eaa2daf - https://godotengine.org
2022-04-07 22:02:10.127262-0400 [37033:3115785] OpenGL ES 3.0 Renderer: Apple A15 GPU
2022-04-07 22:02:10.128397-0400 [37033:3115785] OpenGL ES Batching: ON
2022-04-07 22:02:10.256622-0400 [37033:3115785] 
2022-04-07 22:02:10.485985-0400 [37033:3115785] AK Error: Failed to set audio session category.: Error: Error Domain=NSOSStatusErrorDomain Code=2003329396 "(null)".
2022-04-07 22:02:10.486186-0400 [37033:3115785] Wwise systems initialisation succeeded
2022-04-07 22:02:10.486413-0400 [37033:3115785] ERROR:  does not have a library for the current platform.
2022-04-07 22:02:10.486431-0400 [37033:3115785]    at: init_library (modules/gdnative/nativescript/nativescript.cpp:1486) - Condition "lib_path.length() == 0" is true.
2022-04-07 22:02:10.486452-0400 [37033:3115785] ERROR: Script does not inherit a Node: res://wwise/bin/waapi-gdnative-debug.gdns
2022-04-07 22:02:10.486462-0400 [37033:3115785]    at: start (main/main.cpp:1832) - Condition "!valid_type" is true. Continuing.

Even with the above errors, the audio works fine other than playing in the background, so I don't know if these are relevant to this issue.

@alessandrofama
Copy link
Owner

I don't think the errors are too relevant:

ERROR: AudioOutputUnitStart failed, code: -50

is a unrelated Godot bug.

AK Error: Failed to set audio session category.: Error: Error Domain=NSOSStatusErrorDomain Code=2003329396 "(null)".

This seems relevant at first glance, the error code is kAudioSessionUnspecifiedError (not very helpful). In my tests posted below, I do not get this error, and background audio still does not work.

ERROR:  does not have a library for the current platform. [...]

The Waapi library didn't get exported (as expected), unrelated but should fix this soon.

I was playing a bit in the iOS simulator today and I think Wwise just suspends the audio engine and ignores the audio session category and audio session category options.

  • In the small integration demo included in the Wwise SDK, background audio does not work even if all settings are correct. You can find the demo in /Applications/Audiokinetic/Wwise 2021.1.../SDK/samples/IntegrationDemo/iOS if you want to try it yourself. They set the Audio Session Category in IntegrationDemoAppDelegate.mm.
  • I looked at the source code of Godot and they actually set the category of AVAudioSession to Ambient. Changing this category to Playback or even removing these parts from the source code (in case they conflict with Wwise's handling of the audio session) did not produce any results.
  • In an example provided by Apple with the same settings, background audio works fine without Wwise.

Based on these tests, I would provisionally assume that this is an internal Wwise issue and not a problem with our integration or with the Godot engine. Please let me know if you manage to make this work(I think the integration demo in the SDK would be the best testing environment to check this). Maybe there is a setting I missed or something else that needs to be done to make background audio work.

@alessandrofama
Copy link
Owner

Won't expect this to be fixed anytime soon. Closing but feel free to reopen if you've got any updates.

@jasonpkovalski
Copy link
Author

@alessandrofama Thank you for looking into this further, and sorry for the delay on my end. I can confirm that I cannot get background audio working even with the Integration Demo provided by Wwise. As far as I can tell, all of the necessary settings seem correct too.

Do you have any ideas on how to proceed? Maybe I just need to contact someone on the Wwise side of things directly? This is a necessary feature for many use cases, and it currently does not seem possible.

@jasonpkovalski
Copy link
Author

@alessandrofama I found out that Wwise 2022.1 will support iOS background audio. I tried the integration demo included in the Wwise 2022.1 Beta Preview 1 and confirmed that the background audio demo does work now. I just wanted to provide an update so you're aware that it was, in fact, an issue with Wwise and also that it will be resolved relatively soon in an upcoming release!

@alessandrofama
Copy link
Owner

Interesting, that's good to know, thank you for updating this issue! Then it will probably work with this integration as well. I will support 2022 once it is out of beta. It should be easy to upgrade after possible API changes are fixed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants