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.
3
Answers
I edited the pubspec.yaml file, THIS:
TO THIS:
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.
you are not informing the correct path to the file, try this:
Seems like incorrect path. You have added the path in pubspec.yaml as
- assets/electric.mp3
.Assuming you have added the mp3 in the assets folder.
So use the same path in the code.