I use this ExoPlayer demo for playing audio streaming.
I modified code for playing audio with notification.
for this I put Exoplayer code in service class, but pause method not working don't know what happens but setPlayWhenReady(false)
not working in service. Check this modified source code
That's because every time you setPlayWhenReady(false) , the onPlayerStateChanged
method of ExoPlayer Listener Called and you are setting setPlayWhenReady(true)
in the listener.
So that's what you need to do :
1. define a field in your service :
boolean isPreparing;
2. set isPreparing = true
before initializing the ExoPlayer :
isPreparing = true;
player.prepare(...);
3. in the onPlayerStateChanged
method of ExoPlayer Listener :
@Override
public void onPlayerStateChanged(boolean playWhenReady, int playbackState) {
if(isPreparing && playbackState == ExoPlayer.STATE_READY){
// do whatever you want
isPreparing = false;
}
}
And that's it.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With