-
Notifications
You must be signed in to change notification settings - Fork 404
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to set defaultPositionUs of a Window in the Timeline? #1129
Comments
I think you can do this only if you own the media. This is AFAIK used with live streams. The feature request for VOD is a duplicate of #6373 and #1041 I think. You can use If this isn't helpful you need to use a seek for this. This was discussed in #1041 |
I got a solution based on this google/ExoPlayer#9122 (comment): class MyMediaSource(mediaSource: MediaSource, private val startPositionMs: Long): WrappingMediaSource(mediaSource) {
override fun onChildSourceInfoRefreshed(newTimeline: Timeline) {
super.onChildSourceInfoRefreshed(MyTimeline(newTimeline, startPositionMs))
}
class MyTimeline(timeline: Timeline, private val startPositionMs: Long): ForwardingTimeline(timeline) {
override fun getWindow(windowIndex: Int, window: Window, defaultPositionProjectionUs: Long): Window {
return super.getWindow(windowIndex, window, defaultPositionProjectionUs).apply {
defaultPositionUs = Util.msToUs(startPositionMs)
}
}
}
} val defaultMediaSourceFactory = DefaultMediaSourceFactory(this)
val mediaSourceFactory = object : MediaSource.Factory {
override fun setDrmSessionManagerProvider(drmSessionManagerProvider: DrmSessionManagerProvider): MediaSource.Factory {
return defaultMediaSourceFactory.setDrmSessionManagerProvider(drmSessionManagerProvider)
}
override fun setLoadErrorHandlingPolicy(loadErrorHandlingPolicy: LoadErrorHandlingPolicy): MediaSource.Factory {
return defaultMediaSourceFactory.setLoadErrorHandlingPolicy(loadErrorHandlingPolicy)
}
override fun getSupportedTypes(): IntArray {
return defaultMediaSourceFactory.supportedTypes
}
override fun createMediaSource(mediaItem: MediaItem): MediaSource {
return MyMediaSource(
defaultMediaSourceFactory.createMediaSource(mediaItem),
mediaItem.mediaMetadata.extras?.getLong("startPositionMs") ?: 0,
)
}
}
player = ExoPlayer.Builder(this)
.setMediaSourceFactory(mediaSourceFactory)
.build() |
I want to set default start positions of my playlist items (basically to resume from where the user left), to use when playlist item auto transitions to next item.
As per my understanding (I am not sure), the default start position is of the window in the timeline.
From Docs: Timeline.Window.defaultPositionUs. But, I can't find a way to set this defaultPositionUs parameter.
I use this function to set playlist items: setMediaItems. My playlist items are mp3 files (local and https source).
The text was updated successfully, but these errors were encountered: