How to play local mp3 file with audioplayer 0.2.0 in Flutter.
pubspec.yaml
flutter:
assets:
- sounds/music.mp3
main.dart
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);
}
Can I get local assets path from rootBundle?
Can I pay audio from ByteData on audioPlayer?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…