Comments (2)
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()
from media.
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 MediaItem.ClippingProperties
to clip a media item. However, this removes the part before the clipping start position. A user can't seek back beyond this because it's clipped. So this isn't exactly the same as a start position but about the same as a default position. :)
If this isn't helpful you need to use a seek for this. This was discussed in #1041
from media.
Related Issues (20)
- Splitting HLS stream into multiple MediaItems each with start and end positions
- Crash on playback in onAudioCapabilitiesChanged HOT 2
- How To play encrypted video using ExoPlayer HOT 1
- Playback of AAC audio is choppy, only when played after specific other AAC audio file
- Achieving seamless playback while also setting pauseAtEndOfMediaItems = true
- System UI crashes when switch songs very fast HOT 2
- Video not rendered when using AspectRatioFrameLayout.RESIZE_MODE_FIXED_HEIGHT on Pixel phones HOT 2
- ANR when tap seek to button and play/pause button simultaneously
- MediaSessionService Never Destroy, Once App is Cleared Without Pausing Media HOT 8
- Clarification about DASH-Thumbnails support in exoplayer HOT 7
- Allow overriding drawables locally (only for a specific PlayerView instance) HOT 3
- The widevine dash video playback failed on an Android 8 device(ASUS), errorCode=ERROR_CODE_DRM_PROVISIONING_FAILED. HOT 7
- Midroll playback issue with the first AD Unit (Exoplayer) - first ad unit is skipped HOT 2
- Long running HLS live stream randomly produces an IndexOutOfBoundsException HOT 5
- How to detect when the playback position is behind the live window? HOT 2
- In Media3 how to update the title in notification dynamically during playback HOT 1
- Provide example of MediaItem as an image in Main Demo HOT 4
- The height and width are reversed when using Presentation and Transformer #581 HOT 2
- Exoplayer media3 Drm clearkey Not working HOT 4
- update api ' com.google.android.gms:play-services-cast-framework:21.3.0' to gms:play-services-cast-framework:21.4.0 returns error for build HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from media.