I creating a music player in flutter using audioplayers as package but couldn't find way to play next and previous song in the list.
Asked
Active
Viewed 1,248 times
0

spydon
- 9,372
- 6
- 33
- 63

Digamber negi
- 407
- 1
- 7
- 20
-
1Add codes of what you have tried so far – Kaushik Chandru Jul 29 '22 at 13:04
-
@KaushikChandru I just need reference to docs which i couldn't find for playing next and previous in audioplayers package. – Digamber negi Jul 30 '22 at 06:47
1 Answers
2
For example lets say you have a list of audio files
List<String> allAudio = [
'https://luan.xyz/files/audio/coins.wav',
'https://luan.xyz/files/audio/laser',
'https://luan.xyz/files/audio/ambient_c_motion.mp3',
'https://luan.xyz/files/audio/nasa_on_a_mission.mp3'
];
Now create an index to know which element is the current index
int index = 0;
Noe to change the source of the audio you just have to call
await player.setSource(allAudio[index]);
And set state.. when the next button is clicked add one to the index and call the above-mentioned code to set source..
Make sure you dont increment if the length of list -1 is achieved ..
You can use this package

Kaushik Chandru
- 15,510
- 2
- 12
- 30
-
Thank you @KaushikChandru it works fine but couldn't find their documentation helpful, mostly outdated ones are there. – Digamber negi Jul 30 '22 at 17:13
-
Glad it was helpful. yeah they only added setSource for players. Please accept my answer if it was helpful – Kaushik Chandru Jul 30 '22 at 17:18