1

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.

Venkat
  • 11
  • 2
  • I would like to add another point here when I seek or forward/rewind 10secs video on youtube then media session returns getPosition() correctly. – Venkat Apr 04 '20 at 03:41
  • First, edit your original question instead of adding information in the comments section. Second, please post some codes to help us understand what do you want to do, and how you are trying to do it. – hiddeneyes02 Apr 04 '20 at 07:20

1 Answers1

1

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);
A-run
  • 470
  • 4
  • 13