Search code examples
javaandroidvideodatasourceexoplayer

Exoplayer custom DataSource: Is there a way to make player ask for big chunks of data?


I have implemented custom DataSource to use with ProgressiveMediaSource.

private MediaSource buildMediaSource() {
    MyDataSource.Factory factory = new MyDataSource.Factory(getItem());
    return new ProgressiveMediaSource.Factory(factory).createMediaSource(Uri.EMPTY);
}

When I try to open several MKV files, the player calls read(byte[] buf, int offset, int readLength) function multiple times, passing 1 as readLength.

This results into minutes of initialization time before video starts playing (player wants to read 600000 times by 1 byte on the video I have)

For a test I've setup my own http server and formed an uri for this video, which I then used like this:

new ProgressiveMediaSource.Factory(new DefaultHttpDataSourceFactory("sdfsdfds")).createMediaSource(uri); // uri looks like http://127.0.0.1:34567/video.mkv

and then player began to request 16384 as readLength. Video initialization takes few seconds.

Is there a way for me to tell player to read bigger chunks? Or maybe there is a way to tell MatroskaExtractor to ignore some unwanted things? I still need seeking though


Solution

  • My problem was that for each read() I had to call some functions from native library, resulting in converting java structures to c++ and then back to java to get response.

    This is very heavy operation for just 1 byte. Quick tests showed that preloading big chunks of data on java side speeds up initialization from minutes to seconds.