ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

How should I set up the cache when I don't know if it's live or not.

Open lsgfly opened this issue 3 years ago • 1 comments
trafficstars

When play the hls , I use CacheDataSource.Factory. Because I hope that I can use media cache when it is not live.

When the video is live, only a short segment can be played. I think it should be the reason that m3u8 is already cached.

now how should i handle it.

lsgfly avatar Aug 08 '22 12:08 lsgfly

I have not tested this but I don't think it is straightforward or even possible. If the content is live, it's likely that the playlist contains date information, therefore the segments are stale/expired quite soon after they are being played.

@marcbaechinger are you aware if the player can play cached live streams?

christosts avatar Aug 10 '22 15:08 christosts

To answer the question in short: do not setup the cache in case of a live stream.

ExoPlayer doesn't support downloading live streams. Because of this you have to make sure that you are not using a CacheDataSource with a live stream. Without this, the behaviour is kind of undefined which may result in the behaviour that you report above.

I can't give you a really useful advise I'm afraid. I think you need to know before creating the media source whether it is about a live stream.

ExoPlayer only knows whether a stream is live or not after the media source is prepared. That's obviously too late as the DataSource for the media source need to be setup before the media source can be prepared.

In theory, there would (probably) be a way to have a Cache that is aware whether a given span belongs to a live stream or not and does only cache for VOD. In practice this may be a bad advice though as it is not thought-through, potentially complicated (or at least not straight-forward) to implement, may introduce other problems and we are not able to give support for someone implementing such a feature.

marcbaechinger avatar Aug 22 '22 15:08 marcbaechinger