void initState() {
_myAudioPlayer = AudioPlayer()..setAsset("electric.mp3");
super.initState();}
这是我的代码,这是 pubspec.yaml 文件:
flutter:
assets:
- assets/electric.mp3
它可以在像 Chrome 这样的网络构建上加载文件,但我都尝试了模拟器和真实手机(两个 API 都是 33)。它只是说:
E/ExoPlayerImplInternal( 8300): Playback error
E/ExoPlayerImplInternal( 8300): com.google.android.exoplayer2.ExoPlaybackException: Source error
E/flutter ( 8260):
[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled
Exception: Unable to load asset: "electric.mp3".
E/flutter ( 8260): The asset does not exist or has empty data.
你没有告知正确的文件路径,试试这个:
initState() {
_myAudioPlayer = AudioPlayer()..setAsset("assets/electric.mp3");
super.initState();
}
似乎路径不正确。您已经在 pubspec.yaml 中添加了路径 as
- assets/electric.mp3
.
假设你已经在 assets 文件夹中添加了 mp3。 所以在代码中使用相同的路径。
void initState() {
_myAudioPlayer = AudioPlayer()..setAsset("assets/electric.mp3");
super.initState();
}
我编辑了 pubspec.yaml 文件,这:
flutter:
assets:
- assets/electric.mp3
对此:
flutter:
assets:
- assets/
我之前也删除了“/”。所以主要的解决方案是在文件夹名称的末尾加上“/”。我不知道这一点,因为 Chrome 接受了它。