The AssetAudioPlayerGroup.add() works perfectly, which adds them to list audios and plays the sounds simultaneously.
But if we try to remove a specific asset sound/audio with AssetAudioPlayerGroup.removeAudio() ( when mutilple audios/sounds are present in the list : audios playing simultaneously ) . It removes all the sounds/audios . When it should only remove that specific audio. How can we solve this??
Small code to reproduce
I can't write the code, but here a quick look at what I am doing.
I am using a function, to remove the audio, where I am getting my assets saved in a list which is passed by provider-> RelaxSoundsProvider
final AssetsAudioPlayerGroup audioPlayerGroup = AssetsAudioPlayerGroup(updateNotification: null);
void removeAudios() {
setState(() {
var provider = Provider.of<RelaxSoundsProvider>(context, listen: false);
indexAPG = getIndexGroup();
audioPlayerGroup.stop(); // to stop the audio
//audioPlayerGroup.playingAudios.removeAt(indexAPG); **// even tried this**
audioPlayerGroup.removeAudio(audioPlayerGroup.audios[indexAPG]); **// removing the specific audio**
print('removed content from audio: ${audioPlayerGroup.playingAudios}');
print('removed content from Playing Audio: ${audioPlayerGroup.audios}');
});
}
**// to get indexAPG**
int getIndexGroup() {
var provider = Provider.of<RelaxSoundsProvider>(context, listen: false);
var index = audioPlayerGroup.audios.indexWhere((sng) {
return sng.path == provider.relaxSounds[provider.index].audio.path;
**// where provider.index is same as the index of the sound that we selected to be played**
print('returned index : $index');
return index;
}
**// to add the song to be played**
audioPlayerGroup.add(
provider.relaxSounds[index].audio,
volume: provider.volume, //? Can pass volume here
// loopMode: LoopMode.playlist,
);
@florent37 @kalismeras61 If I have somehow not clearly explained the issue please let me know. I would explain it much better. The thing is I am stuck with this problem for many days now.
Flutter Version
My version : Flutter 1.22.3
Lib Version
My version : assets_audio_player: ^2.0.7+8
Platform (Android / iOS / web) + version
Platform : Android 8.1.0
Describe the bug
The AssetAudioPlayerGroup.add() works perfectly, which adds them to list audios and plays the sounds simultaneously. But if we try to remove a specific asset sound/audio with AssetAudioPlayerGroup.removeAudio() ( when mutilple audios/sounds are present in the list : audios playing simultaneously ) . It removes all the sounds/audios . When it should only remove that specific audio. How can we solve this??
Small code to reproduce
I can't write the code, but here a quick look at what I am doing.
I am using a function, to remove the audio, where I am getting my assets saved in a list which is passed by provider-> RelaxSoundsProvider
List relaxSounds = [
RelaxSounds(
id: 1,
name: 'Camp Fire',
audio: Audio('assets/audio/campfire.mp3'),
icon: Icons.fireplace_outlined,
),
RelaxSounds(
id: 2,
name: 'Coffee Shop',
audio: Audio('assets/audio/coffeeShop.mp3'),
icon: Entypo.cup,
),
...
];
Here's the code logic: