In Android MediaSessionCompat.Callback onSeekTo() how to detect event is from the notification player

103 views Asked by At

The MediaSessionCompat.Callback onSeekTo() callback always passes the absolute position in the media being played. However, there are cases in my app that deal at the chapter level (the entire media is broken into various chapters). Sometimes the player (including the player controls shown in the notification) does seeks relative to a chapter.

Is there a way to find the origin on the seek operation in the seek callback?

class MyMediaSessionCallbackHandler: MediaSessionCompat.Callback() {
    ...
    override fun onSeekTo(position: Long) {
        // sometimes a relative offset is passed
        // how to get that information - is the offset relative or absolute?
    }
}

I understand that the concept of "chapter" is outside the scope of media session itself, just wondering if there is a way to add some context to the media session that can qualify seek callback?

I am using androidx.media:media:1.6.0 and Exoplayer version 2.17.1

1

There are 1 answers

0
rysv On BEST ANSWER

Apparently, this is not possible and has to be managed externally. One option would be to embed a marker in the position sent by the player - for example, add an arbitrarily large offset. And in the onSeekTo() callback detect this shift and use that to determine whether the position originated from the app or outside of it.