Search code examples
flutterjust-audio

just_audio: Why does my audio player work the first time but not the second time?


Tagging this with the appropriate tag so that the repo author can see it.

When my app uses an audio file saved on the user's phone, it works just fine the first time. It shows the audio source as:

justAudioPlayer.audioSource: Instance of 'ProgressiveAudioSource'
playerState: playing=true,processingState=ProcessingState.ready

When I hit the back button (Navigator.pop()) and then go back into the screen and try to play the audio source again, the audio source is now null:

justAudioPlayer.audioSource: null
playerState: playing=true,processingState=ProcessingState.idle

Solution

  • This is likely a simple programming error with your app's state management which, for example, results in your creating a new player instance instead of reusing the same instance.

    (Copied from my comment above since you confirmed it was the correct answer)