Skip to content

iOS audio playback behavior - requests for change #19197

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

Closed
hrydgard opened this issue May 27, 2024 · 7 comments · Fixed by #19200
Closed

iOS audio playback behavior - requests for change #19197

hrydgard opened this issue May 27, 2024 · 7 comments · Fixed by #19200

Comments

@hrydgard
Copy link
Owner

hrydgard commented May 27, 2024

I've gotten two requests of changes to audio behavior:

  • One user wants audio to continue even if the device is in silent mode. Apparently this is common in games and apps, sometimes as a setting.
  • Another user commented that his music playback from another app got quiet when PPSSPP starts, and he'd like to be able to play other audio in the background (EDIT: now, multiple comments like this)

I assume these behaviors are just controlled by various flags to the CoreAudio API, so need to track down documentation and figure out what we want to set.

@hrydgard hrydgard added this to the v1.18.0 milestone May 27, 2024
@hrydgard hrydgard added the Audio label May 27, 2024
@hrydgard
Copy link
Owner Author

Googled and didn't find much, but according to ChatGPT, something like this will do the trick:

@import AVFoundation;

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
    AVAudioSession *audioSession = [AVAudioSession sharedInstance];
    NSError *error = nil;

    BOOL success = [audioSession setCategory:AVAudioSessionCategoryAmbient withOptions:AVAudioSessionCategoryOptionMixWithOthers error:&error];
    if (!success) {
        NSLog(@"Failed to set audio session category: %@", error);
    }

    success = [audioSession setActive:YES error:&error];
    if (!success) {
        NSLog(@"Failed to activate audio session: %@", error);
    }

    return YES;

Will try it soon.

@hrydgard
Copy link
Owner Author

hrydgard commented May 27, 2024

It seems the two goals are contradictory, so we need a setting. For apps to keep playing when silent mode is on, it cannot share the output with other apps using the mixwithothers flag. Also need to use the AVAudioSessionCategoryPlayback mode, not Ambient.

@hrydgard
Copy link
Owner Author

OK, so my current idea for a design is two modes:

  • Exclusive audio mode - will play even when silenced, will silence other apps
  • Mix mode - will mix with other apps, will not play when device silenced

What are these called in other apps?

When an external display is connected, we already switched to Exclusive mode, effectively.

@hrydgard
Copy link
Owner Author

hrydgard commented May 27, 2024

Delta has a rather complex audio manager that manually looks at the mute switch and adjusts volume accordingly, but always runs in mix mode: https://github.com/rileytestut/DeltaCore/blob/main/DeltaCore/Emulator%20Core/Audio/AudioManager.swift

I think we can get pretty far with something much simpler like the above.. But eventually I suppose we might end up doing something similar, we'll see.

@hrydgard
Copy link
Owner Author

hrydgard commented May 27, 2024

Hm, actually there are three modes that are achievable:

  • Exclusive playback, don't respect silent mode
  • Mix with others, don't respect silent mode
  • Mix with others, respect silent mode

Exclusive playback + respect silent mode doesn't seem to be possible. So maybe two checkboxes as UI isn't appropriate.

EDIT: Actually, the fourth mode is possible, so no problem here.

@anr2me
Copy link
Collaborator

anr2me commented May 27, 2024

So, either using 2 checkboxes or a single dropdown with 3 options?

@hrydgard
Copy link
Owner Author

I discovered that the fourth mode is actually possible. So I'm going with two checkboxes.

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

Successfully merging a pull request may close this issue.

2 participants