简体   繁体   English

Exoplayer 自定义数据源:有没有办法让玩家请求大块数据?

[英]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 .我已经实现了自定义DataSource以与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 .当我尝试打开多个 MKV 文件时,播放器多次调用read(byte[] buf, int offset, int readLength) function,将1作为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)这导致视频开始播放前的几分钟初始化时间(播放器想要在我拥有的视频上按 1 个字节读取 600000 次)

For a test I've setup my own http server and formed an uri for this video, which I then used like this:为了进行测试,我设置了自己的 http 服务器并为该视频创建了一个 uri,然后我将其使用如下:

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 .然后播放器开始请求16384作为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?或者也许有办法告诉 MatroskaExtractor 忽略一些不需要的东西? I still need seeking though我仍然需要寻找

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.我的问题是,对于每个 read(),我都必须从本机库中调用一些函数,导致将 java 结构转换为 c++,然后返回到 java 以获得响应。

This is very heavy operation for just 1 byte.对于仅 1 个字节,这是非常繁重的操作。 Quick tests showed that preloading big chunks of data on java side speeds up initialization from minutes to seconds.快速测试表明,在 java 端预加载大块数据可将初始化速度从几分钟缩短到几秒钟。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM