florent37 / Flutter-AssetsAudioPlayer

Play simultaneously music/audio from assets/network/file directly from Flutter, compatible with android / ios / web / macos, displays notifications
https://pub.dartlang.org/packages/assets_audio_player
Apache License 2.0
740 stars 337 forks source link

Unable to play audio in background if spotify is playing in IOS. #602

Open aadesh93 opened 2 years ago

aadesh93 commented 2 years ago

Flutter Version

My version : 2.2.3

Lib Version

My version : 3.0.3+6

Platform (Android / iOS / web) + version

Platform : IOS

Describe the bug

My app triggers the audio player in the background after reaching a certain geofence. This works fine in android. But in IOS the player starts playing audio under normal circumstances. But if the app is running in background and a music player is playing then the player does not play audio.

The expected behaviour in IOS should be ducking of the audio that is currently playing for the duration our audio player plays the audio.

Small code to reproduce


await assetsAudioPlayer.open(
                  Audio.network(poi_list[index].audioUrl),
                  autoStart: true,
                  respectSilentMode: false,
                  showNotification: false,
                  forceOpen: true,
                  playInBackground: PlayInBackground.enabled,
                  audioFocusStrategy: AudioFocusStrategy.request(
                      resumeOthersPlayersAfterDone: true,
                      resumeAfterInterruption: true));
aadesh93 commented 2 years ago

@kalismeras61 Can you give some insights on this?

GaelleJoubert commented 1 year ago

Hello @aadesh93 , I am in a similar situation, My app is having a background process scanning stuff in bluetooth, and when I get a specific message, I would like the app to play a sound. So the playSound() function is triggered from my Background process (which is actually a forground service). It works well in android. But it doesn't work at all in IOS. Even when I have no music player.

Does it works for you for IOS when you don't have an audio player ?

If yes, car you tell me which background process do you use ? Thanks a lot.