From baf5541d57437e40d0dbb3da8d9741ff3ba5e728 Mon Sep 17 00:00:00 2001 From: Salman Alshamrani Date: Sun, 15 Dec 2024 01:39:55 -0500 Subject: [PATCH] Fix iOS audio session allowing other audio to mix --- osu.Framework.iOS/GameApplication.cs | 4 ++++ osu.Framework/Audio/AudioManager.cs | 4 ++-- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/osu.Framework.iOS/GameApplication.cs b/osu.Framework.iOS/GameApplication.cs index fa63f297e1..043800c7fa 100644 --- a/osu.Framework.iOS/GameApplication.cs +++ b/osu.Framework.iOS/GameApplication.cs @@ -38,6 +38,10 @@ public static unsafe void Main(Game target) private static unsafe int main(int argc, byte** argv) { var audioSession = AVAudioSession.SharedInstance(); + + // Set the default audio session to one that obeys the mute switch and does not mix with other audio, + // and insert an observer to disregard the mute switch when the user presses volume up/down. + audioSession.SetCategory(AVAudioSessionCategory.SoloAmbient); audioSession.AddObserver(output_volume_observer, output_volume, NSKeyValueObservingOptions.New, 0); host = new IOSGameHost(); diff --git a/osu.Framework/Audio/AudioManager.cs b/osu.Framework/Audio/AudioManager.cs index f6c366271d..91a4e37d7a 100644 --- a/osu.Framework/Audio/AudioManager.cs +++ b/osu.Framework/Audio/AudioManager.cs @@ -406,8 +406,8 @@ protected virtual bool InitBass(int device) // without this, if bass falls back to directsound legacy mode the audio playback offset will be way off. Bass.Configure(ManagedBass.Configuration.TruePlayPosition, 0); - // For iOS devices, set the default audio policy to one that obeys the mute switch. - Bass.Configure(ManagedBass.Configuration.IOSMixAudio, 5); + // Set BASS_IOS_SESSION_DISABLE here to leave session configuration in our hands (see iOS project). + Bass.Configure(ManagedBass.Configuration.IOSSession, 16); // Always provide a default device. This should be a no-op, but we have asserts for this behaviour. Bass.Configure(ManagedBass.Configuration.IncludeDefaultDevice, true);