Giter Site home page Giter Site logo

Comments (2)

akshdeep-singh avatar akshdeep-singh commented on June 5, 2024 1

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.

marcbaechinger avatar marcbaechinger commented on June 5, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.