diff --git a/Core/Config.cpp b/Core/Config.cpp index 81304f6b0a..dc3f5cd330 100644 --- a/Core/Config.cpp +++ b/Core/Config.cpp @@ -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), }; diff --git a/UI/GameSettingsScreen.cpp b/UI/GameSettingsScreen.cpp index c789a09a55..9fc1a1b4d5 100644 --- a/UI/GameSettingsScreen.cpp +++ b/UI/GameSettingsScreen.cpp @@ -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); diff --git a/android/jni/app-android.cpp b/android/jni/app-android.cpp index 84daae7224..3acef1f261 100644 --- a/android/jni/app-android.cpp +++ b/android/jni/app-android.cpp @@ -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; } diff --git a/android/src/org/ppsspp/ppsspp/PpssppActivity.java b/android/src/org/ppsspp/ppsspp/PpssppActivity.java index 55ada7d424..3ad41acc12 100644 --- a/android/src/org/ppsspp/ppsspp/PpssppActivity.java +++ b/android/src/org/ppsspp/ppsspp/PpssppActivity.java @@ -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;