Android Media session playbackstate doesn’t notify position updates

1.6k views Asked by At

Android media session playbackstate doesn’t notify position update after pause and play. GetPlaybackPosition() returns the same position set at Pause during rest of play. Any clue? Thanks.

1

There are 1 answers

0
A-run On

You have to set a new Playback state for current MediaSession by calling MediaSession.setPlaybackState (PlaybackState state) whenever you play/pause your media. So when you call getPlaybackPosition() it will return the updated state. Whenever you play/pause Media, then get the current position by calling MediaPlayer.getCurrentPosition() and set this for current MediaSession. Something like this

PlaybackState state = new PlaybackState.Builder()
                .setState(PlaybackState.STATE_PLAYING,
                        MediaPlayer.getCurrentPosition(), PLAYBACK_SPEED)
                .build();
MediaSession.setPlaybackState(state);