英文:
Exoplayer custom DataSource: Is there a way to make player ask for big chunks of data?
问题
我已经实现了自定义的DataSource
,用于与ProgressiveMediaSource
一起使用。
private MediaSource buildMediaSource() {
MyDataSource.Factory factory = new MyDataSource.Factory(getItem());
return new ProgressiveMediaSource.Factory(factory).createMediaSource(Uri.EMPTY);
}
当我尝试打开多个MKV文件时,播放器多次调用read(byte[] buf, int offset, int readLength)
函数,将1
作为readLength
传递。
这导致视频开始播放之前数分钟的初始化时间(在我所拥有的视频上,播放器希望以1个字节为单位读取600000次)。
为了进行测试,我设置了自己的http服务器,并为该视频形成了一个URI,然后像这样使用它:
new ProgressiveMediaSource.Factory(new DefaultHttpDataSourceFactory("sdfsdfds")).createMediaSource(uri);
// uri的格式类似于 http://127.0.0.1:34567/video.mkv
然后播放器开始请求16384
作为readLength
。视频初始化只需几秒钟。
我是否有办法告诉播放器读取更大的数据块?
或者也许有一种方法可以告诉MatroskaExtractor忽略一些不需要的内容?尽管我仍然需要能够进行跳转。
英文:
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
答案1
得分: 1
我的问题是,对于每个read(),我都需要调用一些来自本地库的函数,导致将Java结构转换为C++,然后再转换回Java以获取响应。
这对于只有1字节的操作来说非常耗费资源。快速测试显示,在Java端预加载大块数据可以将初始化速度从几分钟加快到几秒钟。
英文:
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.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论