skip to Main Content
 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


  1. Chosen as BEST ANSWER

    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.


  2. you are not informing the correct path to the file, try this:

    initState() { 
      _myAudioPlayer = AudioPlayer()..setAsset("assets/electric.mp3");
     super.initState();
    }
    
    Login or Signup to reply.
  3. 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.

       void initState() { 
        _myAudioPlayer = AudioPlayer()..setAsset("assets/electric.mp3");
        super.initState();
        }
    
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search