如何在Flutter中使用audioplayer 0.2.0播放本地mp3文件。
pubspec.yaml
flutter:
assets:
- sounds/music.mp3
Future<ByteData> loadAsset() async {
return await rootBundle.load('sounds/music.mp3');
}
// FIXME: This code is not working.
Future playLocal() async {
final result = await audioPlayer.play(loadAsset());
if (result == 1) setState(() => playerState = PlayerState.playing);
}
我能从rootBundle获得本地资源路径吗? 我能在audioPlayer上使用ByteData支付音频吗?