google / google/ExoPlayer

Extend isAtomic flag in ConcatanatingMediaSource to actually merge timelines

Open
#4,868 5 comments 1 reaction 1 assignee Claimed by @tonihei View on GitHub
enhancement
Dominant language
Java
Stars
21.9k
Forks
6k
PR merge metrics
No merged PRs in 30d

Description

Similar to [this issue](https://github.com/google/ExoPlayer/issues/2122), 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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.