颤振just_audio无法在安卓版本上加载音频资产


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.

我编辑了pubspec。

flutter:
assets:
- assets/electric.mp3

:

flutter:
assets:
- assets/

我正在删除"/"太过。所以主要的解决方案是使用"/"在文件夹名称的末尾。我不知道这个,因为Chrome接受它。

你没有告诉正确的路径到文件,试试这个:

initState() { 
_myAudioPlayer = AudioPlayer()..setAsset("assets/electric.mp3");
super.initState();
}

似乎是错误的路径。您已经在pubspec中添加了路径。yaml是

- assets/electric.mp3.

假设您已经在assets文件夹中添加了mp3。所以在代码中使用相同的路径。

void initState() { 
_myAudioPlayer = AudioPlayer()..setAsset("assets/electric.mp3");
super.initState();
}