1

I needed some help regarding using audioplayer package in flutter, i found a piece of code thats understandable except the PlayerState.PLAYING part, is this PlayerState a part of audioPlayers package or what?

Code:

 //listen to states: playing paused stopped
    audioPlayer.onPlayerStateChanged.listen((state){
      setState(() {
        isPlaying = state == PlayerState.PLAYING;
      });
    });

Also if anyone can tell the right way to listen to states using audioPlayers.

Elle Bishop
  • 307
  • 11

3 Answers3

1

Dart wasn't recognizing PlayerState.PLAYING because PLAYING is deprecated and now you can write instead PlayerState.playing and it works just fine now.

Elle Bishop
  • 307
  • 11
1

Check this official documentation here to get your correct answer. Currently I guess its PlayerState.playing used.

0

Yes, it is part of the audio_players package. Packages on pub.dev are Open Source. This means you can easily look at the code.

Open https://pub.dev/packages/audioplayers

Select Repository (Github) in the side menu for the GitHub repostiory.

Press "." on your keyboard, this opens VS Code in the browser.

Search for PlayerState, you will find many results. PlayerState is probably a class or enum and if you look it up you will find the enum PlayerState under src/api/player_state.dart.

Normally this is not necessary, because you can navigate with Command + Left Click on your PlayerState directly to the place in your IDE. Under Mac at least.

Ozan Taskiran
  • 2,922
  • 1
  • 13
  • 23