将视频流呈现为部分内容而不是完整流 chrome
render video stream as partial content rather than full stream to chrome
我们目前向后端服务器提交视频播放请求,将完整的流作为输入流发送到浏览器中播放 (window)。这工作正常,但增加了复杂性,因为搜索功能在 chrome 中不起作用。建议的解决方案是告诉网络服务器它需要接受一个字节范围,然后以部分字节范围传送流。我不确定这是否能解决问题,但我的问题是如何 return 字节范围内的流,考虑到以下是现在完成的方式:
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(
在发送最终响应之前,初始输入流会传递给很多 类。请有任何想法。
编辑:
我只想了解 html5 与 chrome 的视频问题。有很多关于设置服务器响应 headers 以包含 Accept-Ranges=, Content-length= , Content-Range= 的帖子,这会告诉 chrome 下载字节范围,然后允许搜索功能工作。由于视频播放搜索在 firefox 中有效,我不必更改传输流的方式,或者我会吗?我还需要从服务器提交部分视频吗?以及如何?
我解决了我的情况,无需更改任何流代码,而只是确保将正确的范围 headers 应用于响应以确保 chrome 处理播放。
Accept-Ranges: bytes
Content-Range: bytes 0-1025/905357
Content-Length: 905357
我们目前向后端服务器提交视频播放请求,将完整的流作为输入流发送到浏览器中播放 (window)。这工作正常,但增加了复杂性,因为搜索功能在 chrome 中不起作用。建议的解决方案是告诉网络服务器它需要接受一个字节范围,然后以部分字节范围传送流。我不确定这是否能解决问题,但我的问题是如何 return 字节范围内的流,考虑到以下是现在完成的方式:
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(
在发送最终响应之前,初始输入流会传递给很多 类。请有任何想法。
编辑:
我只想了解 html5 与 chrome 的视频问题。有很多关于设置服务器响应 headers 以包含 Accept-Ranges=, Content-length= , Content-Range= 的帖子,这会告诉 chrome 下载字节范围,然后允许搜索功能工作。由于视频播放搜索在 firefox 中有效,我不必更改传输流的方式,或者我会吗?我还需要从服务器提交部分视频吗?以及如何?
我解决了我的情况,无需更改任何流代码,而只是确保将正确的范围 headers 应用于响应以确保 chrome 处理播放。
Accept-Ranges: bytes
Content-Range: bytes 0-1025/905357
Content-Length: 905357