I'm trying to use audioplayers: ^2.0.0,but i got this error, how to solve it?please!

1

pubspec.yaml

flutter:
  uses-material-design: true
  assets:
    - assets/audio/

Code

 Future setAudio() async {
    AudioPlayer audioPlayer = AudioPlayer();
    audioPlayer.setReleaseMode(ReleaseMode.loop);

    AudioCache audioCache = AudioCache(prefix: 'assets/audio/');

    final url = await audioCache.load('flip.mp3');
    audioPlayer.setSourceAsset(url.path);
 }
1

There are 1 best solutions below

0
On

You shouldn't use the full path in setSourceAsset, and since you've already set a prefix for the cache you kust have to write the filename:

audioPlayer.setSourceAsset('flip.mp3');