Skip to content

Audio doesn't work on iPhone without extra code to activate AVAudioSession #431

Closed
@oviano

Description

A slightly odd one; audio works fine on all platforms I have tried, which are macOS, tvOS, iOS, Windows and Android...with the exception of my iPhone X.

On this device, it's necessary to have the following lines before starting the audio:

/* activate audio session */
AVAudioSession* audio_session = [AVAudioSession sharedInstance];
[audio_session setCategory: AVAudioSessionCategoryPlayback withOptions:AVAudioSessionCategoryOptionDefaultToSpeaker error:nil];
[audio_session setActive:true error:nil];

...and then presumably these lines to deactivate it afterwards:

/* deactivate audio session */
[[AVAudioSession sharedInstance] setActive:false error:nil];

It's only the iPhone that needs this. An iPad running the same version of iOS (14.2) outputs audio without the above lines.

I tried adding these lines to sokol_audio.h but I started running into problems as these are objective C calls, so maybe it's ok as it is, and the responsibility of the application to deal with this? Seems slightly off-beat that one platform needs this extra initialisation in order to work though.....

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions