Flutter audioplayers audio not playing

3.2k Views Asked by At

I use the audioplayers class and everytime I call the player.play('timer.mp3') it gives me this errer:

Reusing soundId 1 for file:///data/user/0/com.example.secret_app/cache/timer.mp3 is loading=false xyz.luan.audioplayers.WrappedSoundPool@6232270
W/SoundPool(25113): play soundID 1 not READY

my code:

import 'package:audioplayers/audioplayers.dart';
...
class _HomeState extends State<Home> {
  static AudioCache player = AudioCache();
  ...
  initState(() {
    super.initState();
    player.load('timer.mp3');
  })
  ...
   _playSound() {
    player.play('timer.mp3', mode: PlayerMode.LOW_LATENCY, volume: 1);
  }
  ...
}

I also imported the file correctly in the pubpec.yaml file. I have no clue why it doesn't play the sound since it already worked with the same code.

1

There are 1 best solutions below

0
On

If you want to play an audio file, you need to do the following:

In your pubspec.yml, use:

audioplayers: ^1.0.1

then

import 'package:audioplayers/audioplayers.dart';

then go to your class and type:

final audio2 =Audioplayer();
audio2.play(AssetSource('your mp3 or wav file here');

And that's it; it will work perfectly.