ExoPlayer icon indicating copy to clipboard operation
ExoPlayer copied to clipboard

Refreshing the Timeline when using FileDataSource

Open im12345dev opened this issue 3 years ago • 3 comments
trafficstars

I have a very specific case in my app where I download a live stream into a local file, then I am playing the local file using ExoPlayer while the file/stream is being downloaded, ExoPlayer loads and play the file just fine, the issue is the timeline is not updating as the file is being downloaded and decoded and it's not possible to seek after the initial loaded timeline. For example, loading the same file with VLC Lib the timeline update just fine and automatically, is there any way to achieve it with ExoPlayer? if so I would like some guidance.

Edit: I can refresh the timeline correctly by calling notifySourceInfoRefreshed() with the current details of the file and the timeline refreshes correctly, the only issue is the video & audio just freezes once the video past the original duration point. What else do I need to refresh?

im12345dev avatar Jul 25 '22 18:07 im12345dev

This question is similar to #7070 (where an EOFException was seen when reading the partially downloaded file). To support partially loaded files, the player needs to know which data is available and that it needs to wait until more is coming. Ideally, you can use ExoPlayer's download/cache functionality that tells the player how much data is loaded already. Alternatively, you can write your own version of DataSource that blocks read operations until the data is available and doesn't return the current total file size until the file is finished (to avoid the problem that the player believes it has read the entire file already). You may want to write a DataSourceContractTest if you do that to ensure the source fully conforms to the interface.

tonihei avatar Jul 26 '22 07:07 tonihei

Unfortunately using ExoPlayer download/cache functionality is not an option as some of the streams are live streams (and some are not), so I need a solution that would work for both. I will start playing with DataSource and see if I can manage it by writing a custom DataSource, if you have any more guidance it would be much appreciated.

im12345dev avatar Jul 26 '22 14:07 im12345dev

This is getting too customized to provide detailed guidance, but have a look at existing DataSources like FileDataSource or ByteArrayDataSource to see how implementations should look like general. The important bits for your case are:

  • Return C.LENGHT_UNSET from open() to indicate that the overall length is not known yet.
  • Block read() operations until you can return at least one byte of the requested data range and return C.RESULT_END_OF_INPUT once you reach the actual end of the file.

I'd advise you to write a DataSourceContractTest (see for example FileDataSourceContractTest) to ensure your DataSource is fully interface-compliant.

tonihei avatar Jul 27 '22 08:07 tonihei

Closing because the question was answered and we won't be able to provide more detailed guidance.

tonihei avatar Sep 06 '22 09:09 tonihei