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
757 stars 370 forks source link

Player stops when another one starts playing on iOS #426

Open nt4f04uNd opened 3 years ago

nt4f04uNd commented 3 years ago

Flutter Version 1.24.0-8.0.pre.374

Lib Version

2.0.10

Platform

iOS 14.01

Describe the bug

Start player -> start some other audio source -> player stops and I cannot update my UI to respect that On android it will keep playing

Might be helpful https://github.com/flutter/flutter/issues/66799

nt4f04uNd commented 3 years ago

ok i found out isPlaying, gonna test this described behaviour is still not intended though, i want to keep the player playing

nt4f04uNd commented 3 years ago

this is happening with Youtube app in particular im using AudioFocusStrategy.none()

kalismeras61 commented 3 years ago

Are you having problem with only IOS ?

nt4f04uNd commented 3 years ago

yes, this is only related to darwin and here's why - i found that when you don't respectSilence, the audio session category is forced to AVAudioSessionCategoryPlayback, which also makes that controls appear on the lockscreen no matter any other parameters, as well as interrupt and being interruped by other such sessions

https://github.com/florent37/Flutter-AssetsAudioPlayer/blob/89ae26204d7ca312208b3bacb29b68ebbfe61b1c/darwin/Classes/Music.swift#L178-L183

as far a i know this is a general limitation on darwin, you:

i might be wrong as there is quite a few types of categories, which also have some options

so if you are going to work on this issue, i encourage to investigate all this thing, and rework the current package API in that part, because it makes an illusion that it will work, whilst it actually won't. i'm talking about AudioFocusStrategy (mixing with others), respecting silence, showing media controls, stopping playback when screen is locked (and might be something else idk). also, all of the audio session categories should be supported

kalismeras61 commented 3 years ago

@nt4f04uNd I did some changes . Can you try below branch ?

assets_audio_player:
    git:
      url: https://github.com/florent37/Flutter-AssetsAudioPlayer.git
      ref: fix_audiofocus
nt4f04uNd commented 3 years ago

i think it would be better if you could do this yourself, but if you really need me to do this, i'm gonna tomorrow/day after

kalismeras61 commented 3 years ago

@nt4f04uNd i already tried but, As the person reporting the problem, you have to test it.

nt4f04uNd commented 3 years ago

@kalismeras61 sorry for a delayed response - no, AudioFocusStrategy.none() still doesn't work (tested in my app on iPhone 7 iOS 14.3)

if you can provide reproducible builds w/ and w/o fix and share them with me via https://www.installonair.com/home i could test it for you

uugurbas commented 3 years ago

any solutions? I am having the same problem. When trying to play assets several times consecutively it stops playing.