I'm using an assets_audio_player and I faced to some problem when i tryed to use sources from json. I have two screens with my player. First screen is just list with onPressed items, Second screen is a carousel player. When i want to open a Second screen - i want to get a current playlist possition with ability to go back and ahead but my player doesn't work correct.
@override
void initState() {
currentSongs = widget.data['index'];
allSongs = widget.data['songs'];
audioList = loadAudioList();
setupPlaylist();
super.initState();
}
@override
void dispose() {
audioPlayer.stop();
super.dispose();
}
loadAudioList() {
for (var i = 0; i < allSongs.length; i++) {
audio = allSongs[i]['fields']['audio'][0]['url'].toString();
title = allSongs[i]['fields']['name'].toString();
subtitle = allSongs[i]['fields']['type'].toString();
image = allSongs[i]['fields']['cover'][0]['url'].toString();
audioList.add(
Audio.network(audio,
metas: Metas(
title: title, artist: subtitle, image: MetasImage.file(image))),
);
}
return audioList;
}
void setupPlaylist() async {
var list = audioList.length;
print(list);
audioPlayer.open(Playlist(audios: audioList, startIndex: currentSongs),
autoStart: false, showNotification: true, loopMode: LoopMode.none);
}
If i store a static list in List - is okay. but i want to store a dynamic list of music from API. Help me, please.