void initState() {
_myAudioPlayer = AudioPlayer()..setAsset("electric.mp3");
super.initState();}
Here is my code and here is the pubspec.yaml file:
flutter:
assets:
- assets/electric.mp3
It can load the file on the web builds like Chrome but I both tried emulator and a real phone (both APIs are 33). It just saying:
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.
I edited the pubspec.yaml file, THIS:
flutter:
assets:
- assets/electric.mp3
TO THIS:
flutter:
assets:
- assets/
And I was deleting the "/" too before. So the main solution is having the "/" at the end of the folder name. I didn't know this and because Chrome accepts it.