我是 Flutter 的新手,我使用 just_audio 插件創建了一個音樂播放器,但是我在實作要更改當前正在播放的歌曲的 nxt 按鈕時遇到了麻煩。
ListView.builder(
shrinkWrap: true,
physics: const NeverScrollableScrollPhysics(),
itemCount: item.data!.length,
itemBuilder: (context, index) {
return ListTile(
title: Text(item.data![index].title),
trailing: IconButton(
icon: const Icon(Icons.play_arrow),
onPressed: () {
playmusichandler('${item.data![index].uri}');
},
),
噸
void playmusic() async{
try {
await widget.audioPlayer
.setAudioSource(AudioSource.uri(Uri.parse(widget.songModel.uri!)));
await widget.audioPlayer.play();
} catch (e) {
debugPrint('$e');
}
}
==
StreamBuilder<SequenceState?>(
stream: widget.audioPlayer.sequenceStateStream,
builder: (context, index) {
return IconButton(
onPressed: () {
widget.audioPlayer.hasNext
? widget.audioPlayer.seekToNext()
: null;
},
icon: const Icon(
Icons.skip_next,
size: 45.0,
color: Colors.white,
));
}),
uj5u.com熱心網友回復:
重要的是要注意,在這里您正在使用音頻剪輯,這意味著您正在使用單首歌曲。盡管如此,播放串列是just_audio包中的另一個選項。
使用無縫播放串列。
`// Define the playlist
final playlist = ConcatenatingAudioSource(
// Start loading next item just before reaching it
useLazyPreparation: true,
// Customise the shuffle algorithm
shuffleOrder: DefaultShuffleOrder(),
// Specify the playlist items
children: [
AudioSource.uri(Uri.parse('https://example.com/track1.mp3')),
AudioSource.uri(Uri.parse('https://example.com/track2.mp3')),
AudioSource.uri(Uri.parse('https://example.com/track3.mp3')),
],
);
// Load and play the playlist
await player.setAudioSource(playlist, initialIndex: 0, initialPosition: Duration.zero);
await player.seekToNext(); // Skip to the next item
await player.seekToPrevious(); // Skip to the previous item
await player.seek(Duration.zero, index: 2); // Skip to the start of track3.mp3
await player.setLoopMode(LoopMode.all); // Set playlist to loop (off|all|one)
await player.setShuffleModeEnabled(true); // Shuffle playlist order (true|false)
// Update the playlist
await playlist.add(newChild1);
await playlist.insert(3, newChild2);
await playlist.removeAt(3);`
當您與孩子打交道時,您必須將音頻串列傳遞給他們。之后,您可以使用索引來確定當您選擇一首歌曲時將播放哪首歌曲,然后您可以選擇播放上一個或其他選項
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/533178.html
標籤:扑镖
