'Flutter stop all other players for Audio player
I'm developing an app that contain multiple audio files for classroom, how can I stop all other players when I want to play a single audio? I've used Listview builder, and named every audio file with different name but I don't know how to reach them again to stop while they are playing now
I I can play and stop single audio, but if I left one of the audio list playing and play a new one, the old one will keep playing
ListView.builder(
itemCount: 3,
itemBuilder: (context, index) {
return AudioLectureWidget(
mp3URL:index==0?'https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-0.mp3':index==1?'https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-5.mp3':'https://audio-samples.github.io/samples/mp3/blizzard_unconditional/sample-4.mp3',
playerId: 'player$index',
title: 'Introduction to Artificial Intelligence',
subTitle: 'Object Oriented Programming',
time: '56:12',
);
}),
AudioLectureWidget:
onTap: (){
playerId.stop();
!isPlaying?playerId.play(widget.mp3URL) :playerId.stop();
isPlaying = !isPlaying;
setState(() { });
},
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|