【发布时间】:2018-02-09 10:39:28
【问题描述】:
我们目前向后端服务器提交视频播放请求,将完整流作为输入流发送到浏览器(窗口)中播放。这工作正常,但有一个额外的复杂性,因为搜索功能在 chrome 中不起作用。建议的解决方案是告诉网络服务器它需要接受一个字节范围,然后以部分字节范围传送流。我不确定这是否能解决这种情况,但我的问题是如何在字节范围内返回流,考虑到以下是它现在的完成方式:
InputStream is= null;
is = new FileInputStream(ndirectoryFile);
....
//(calling class request)
stream = videoWrapper.getVideo(id, address);
如果我以字节范围读取文件,我是否只是循环浏览文件,但如何发送响应:
InputStream is = new ByteArrayInputStream(new byte[] { 0, 1, 2 });
ByteArrayOutputStream buffer = new ByteArrayOutputStream();
int nRead;
byte[] data = new byte[1024];
while ((nRead = is.read(data, 0, data.length)) != -1) {
buffer.write(data, 0, nRead);
}
buffer.flush();
byte[] byteArray = buffer.toByteArray(
在发送最终响应之前,初始输入流会被传递给很多类。请有任何想法。
编辑:
我只想了解 chrome 的 html5 视频问题。关于设置服务器响应标头以包含 Accept-Ranges=、Content-length=、Content-Range= 的文章很多,这将告诉 chrome 下载字节范围,然后允许搜索功能工作。由于视频播放搜索在 Firefox 中工作,我不应该改变我传递流的方式,还是我会?我还需要从服务器提交视频的部分范围吗?以及如何?
【问题讨论】:
标签: java google-chrome video-streaming html5-video