Description
openedon Sep 26, 2018
Similar to this issue, I need to display a playback position for audio files that represents the position relative to the entirety of a ConcatenatingMediaSource, rather than the position relative to a single window in the timeline.
The solution in the issue above is to use setShowMultiWindowTimeBar
in PlaybackControlView
. But I am not using PlaybackControlView
. I have my own UI that uses a standard Android MediaControllerCompat connection to my MediaBrowserServiceCompat service where Exoplayer is running (connected to the MediaBrowserServiceCompat service using MediaSessionConnector
). So setShowMultiWindowTimeBar
doesn't work for me.
Moreover, I need the timecode to be displayed in the same fashion in any and all media session controller UIs that attach to my media session, including the playback controller that appears in Android's notifications, and potentially in Android Auto and Android Watch should my app ever use them.
So as far as I can tell I need the modified playback position to be broadcast from the playback service itself.
At the moment I am updating the timecode myself, in the service, as follows:
private val updatesRunnable = Runnable {
run {
val currentPosition = mSimpleExoPlayer.currentPosition
val windowIndex = mSimpleExoPlayer.currentWindowIndex
val position = mOffsetsArray[windowIndex] + currentPosition
val playbackStateBuilder = PlaybackStateCompat.Builder()
.setState(PlaybackStateCompat.STATE_PLAYING, position, 0f)
mMediaSessionCompat.setPlaybackState(playbackStateBuilder.build())
}
showUpdates()
}
That mostly works fine, and my UI shows the correct position of the playback relative to the whole playlist, so that, for instance, if the first file is 1 minute long, the second file displays as starting at "00:01:00" rather than starting again at "00:00:00".
But the UI also momentarily shows "00:00:00" whenever Exoplayer moves to the next concatenated file. Somewhere the MediaSessionConnector seems to be setting the MediaSessionCompat play position itself, and it's conflicting with the playback position I have set in the runnable above.
Also, for reasons I don't understand that solution doesn't work for the playback controller in the Android notification panel. It just shows positions starting at 00:00:00 every time the player moves to the next file.
How and where do I get MediaSessionConnector to update the play position so it's relative to all the files in the concatenation, in a way that works for all controllers attached to the session?
Or if that's not possible, how and where do I prevent MediaSessionConnector from updating the play position altogether, so I can just do that myself? I tried setting doMaintainMetadata to false but that doesn't stop MediaSessionConnector's position update as I hoped.
thanks
John