alessandrofama / wwise-godot-integration

Wwise Integration for the Godot Engine
Other
288 stars 14 forks source link

iOS Background Audio Not Working #51

Closed jasonpkovalski closed 2 years ago

jasonpkovalski commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

alessandrofama commented 2 years ago

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 commented 2 years ago

@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 commented 2 years ago

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 commented 2 years ago

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.

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 commented 2 years ago

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

jasonpkovalski commented 2 years ago

@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 commented 2 years ago

@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 commented 2 years ago

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.