Implement the "Mix audio with other apps" setting on Android.

This commit is contained in:
Henrik Rydgård committed 2026-05-31 19:08:45 +02:00
1 parent 93340779e1
commit e8e357e360
4 files changed
+33 -5

No files matched your search

+11 -1
View File
@@ -825,6 +825,16 @@ std::string DefaultProAdhocServer() {
return "socom.cc";
}
bool DefaultAudioMixWithOthers() {
#if PPSSPP_PLATFORM(IOS)
// On iOS, it's generally best to mix with others by default, since users expect that and the hardware is generally good enough to handle it.
return true;
#else
// On Android, we historically took audio focus.
return false;
#endif
}
static const ConfigSetting soundSettings[] = {
ConfigSetting("Enable", SETTING(g_Config, bEnableSound), true, CfgFlag::PER_GAME),
ConfigSetting("ExtraAudioBuffering", SETTING(g_Config, bExtraAudioBuffering), false, CfgFlag::DEFAULT),
@@ -850,7 +860,7 @@ static const ConfigSetting soundSettings[] = {
ConfigSetting("AudioDevice", SETTING(g_Config, sAudioDevice), "", CfgFlag::DEFAULT),
ConfigSetting("AutoAudioDevice", SETTING(g_Config, bAutoSwitchAudioDevice), true, CfgFlag::DEFAULT),
ConfigSetting("AudioMixWithOthers", SETTING(g_Config, bAudioMixWithOthers), true, CfgFlag::DEFAULT),
ConfigSetting("AudioMixWithOthers", SETTING(g_Config, bAudioMixWithOthers), &DefaultAudioMixWithOthers, CfgFlag::DEFAULT),
ConfigSetting("AudioRespectSilentMode", SETTING(g_Config, bAudioRespectSilentMode), false, CfgFlag::DEFAULT),
ConfigSetting("UseOldAtrac", SETTING(g_Config, bUseOldAtrac), false, CfgFlag::DEFAULT),
};
+2
View File
@@ -661,6 +661,8 @@ void GameSettingsScreen::CreateAudioSettings(UI::ViewGroup *audioSettings) {
System_Notify(SystemNotification::AUDIO_MODE_CHANGED);
});
respectSilentMode->SetEnabledPtr(&g_Config.bEnableSound);
#endif
#if PPSSPP_PLATFORM(ANDROID) || PPSSPP_PLATFORM(IOS)
CheckBox *mixWithOthers = audioSettings->Add(new CheckBox(&g_Config.bAudioMixWithOthers, a->T("Mix audio with other apps")));
mixWithOthers->OnClick.Add([=](EventParams &e) {
System_Notify(SystemNotification::AUDIO_MODE_CHANGED);
+5
View File
@@ -656,6 +656,8 @@ static std::string QueryConfig(std::string_view query) {
}
// Otherwise, some devices prefer the Java init so play it safe.
return "true";
} else if (query == "audioMixWithOthers") {
return g_Config.bAudioMixWithOthers ? "1" : "0";
} else {
return "";
}
@@ -1118,6 +1120,9 @@ void System_Notify(SystemNotification notification) {
case SystemNotification::TEST_JAVA_EXCEPTION:
PushCommand("testException", "This is a test exception");
break;
case SystemNotification::AUDIO_MODE_CHANGED:
PushCommand("audio_mode_changed", "");
break;
default:
break;
}
@@ -737,7 +737,7 @@ public class PpssppActivity extends AppCompatActivity implements SensorEventList
setVolumeControlStream(AudioManager.STREAM_MUSIC);
gainAudioFocus(this.audioManager, this.audioFocusChangeListener);
updateAudioFocus(this.audioManager, this.audioFocusChangeListener);
NativeApp.audioInit();
if (javaGL) {
@@ -1092,7 +1092,7 @@ public class PpssppActivity extends AppCompatActivity implements SensorEventList
mCameraHelper.resume();
}
gainAudioFocus(this.audioManager, this.audioFocusChangeListener);
updateAudioFocus(this.audioManager, this.audioFocusChangeListener);
NativeApp.resume();
mSensorManager.registerListener(this, mAccelerometer, SensorManager.SENSOR_DELAY_GAME);
@@ -1147,9 +1147,17 @@ public class PpssppActivity extends AppCompatActivity implements SensorEventList
// keep this static so we can call this even if we don't
// instantiate NativeAudioPlayer
public static void gainAudioFocus(AudioManager audioManager, AudioFocusChangeListener focusChangeListener) {
if (audioManager != null) {
public static void updateAudioFocus(AudioManager audioManager, AudioFocusChangeListener focusChangeListener) {
if (audioManager == null) {
Log.w(TAG, "Couldn't update audio focus, audio manager null");
return;
}
if (NativeApp.queryConfig("audioMixWithOthers").equals("0")) {
// Shouldn't mix with others - take over.
audioManager.requestAudioFocus(focusChangeListener, AudioManager.STREAM_MUSIC, AudioManager.AUDIOFOCUS_GAIN);
} else {
// Mix with others - abandon focus so we don't kick others out.
audioManager.abandonAudioFocus(focusChangeListener);
}
}
@@ -1710,6 +1718,9 @@ public class PpssppActivity extends AppCompatActivity implements SensorEventList
} else if (command.equals("immersive")) {
updateSystemUiVisibility();
return true;
} else if (command.equals("audio_mode_changed")) {
updateAudioFocus(this.audioManager, this.audioFocusChangeListener);
return true;
} else if (command.equals("recreate")) {
recreate();
return true;