Closed ahaboubi closed 4 years ago
That's default behavior of iOS apps. I was trying to mimic the Android SoundPool API on iOS but iOS application have a single AVAudioSession active and there is no such thing as stream types from Android. If you want your app to allow background music to not be silenced by your app you need to change the AVAudioSession's category according to this guide.
Changing the AVAudioSession's category works as expected.
Thank you!
@ahaboubi I have the same problem. Can provide the code changes that you have done to make it work?
@ahaboubi @deniza I'm not sure I understand the solution "AVAudioSession" you mentioned above. If the music app was my designed app, I agree that I can set AVAudioSession something like mixWithOthers in the music app but it's not mine. Or are you meaning to set AVAudioSession mode in SoundPool? how? Could you share more how you fix it? thanks in advance!
@JmyW I also was not able to fix it with AVAudioSession. So I have switched to the library audioplayers which does not have this problem.
audioplayers library does exactly that: it updates the AVAudioSession config when it is going to play notification sound or something similar. It has way more features (it can also can use Soundpool on Android) but this plugin is focused on simplicity and short sound effects management.
@JmyW Thats the native code you should add somewhere applicable in your ios project. (Runner.xcodeproj)
Personally I put it into some custom plugin function, but I think that you can safely call it from didFinishLaunchingWithOptions in AppDelegate.swift. Also remember to import AVFoundation
@deniza @denniske Got it. thanks for let me know. However just for your reference, I've known some others like audioplayers that support mode "respectSilence" set true during initiation to enable the co-existence with background music. That maybe an idea make this package stronger.
To be honest, I tend to use soundpool rather than audioplayers since I am not designed a "players" but an application. And I'm actually seeing audioplayers' issue when special situation in my code, that's why I'm searching better & tiny solution like soundpool.
On iOS, calling the play method stops any music playing in the background.
To reproduce, open the Music app on iOS (or any other music app) and start playing music. Then open the flutter app and play any sound using the Soundpool play method, the Music app will be interrupted and will stop any playing music.