skip to Main Content

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.

2

Answers


  1. Chosen as BEST ANSWER

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


  2. 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.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search