【发布时间】:2018-02-20 13:41:43
【问题描述】:
我终于使用标题 Content-Range 等在具有搜索功能的 chrome 中播放视频,并返回状态 206。它适用于较小的视频,但不适用于大型视频。请注意,我没有显式发送实际的字节范围,而是将整个流传送到网络服务器。我收到以下错误:
org.eclipse.jetty.io.EofException,
这发生在将整个输入流提供给 servlet 的后端数据服务器中,而 jetty 是正在使用的服务器。我不确定这个过程如何实际播放并纠正我需要的搜索功能,但现在视频播放一段时间后失败。浏览器调试器也会出现如下错误:
ERR_CONTENT_LENGTH_MISMATCH
我有一个音频流同时被请求和播放,因为我不知道如何混合这两个流。
任何想法或建议表示赞赏。
编辑:
感谢将resourcehandler 更改为defaultservlet 的建议;不确定在哪里执行此操作,因此在代码中找到了 this 在哪里的实例:
private void addHttpContexts(ConfigNode cnode) throws Exception {
try {
// get all the http context nodes
ConfigNode[] httpContextNodes = cnode.getChildNode("HttpContextList").getChildNodes();
for (int s = 0; s < httpContextNodes.length; s++) {
String urlPath = httpContextNodes[s].getChildNode("ContextPath").getStringValueEx();
String resourceBase = httpContextNodes[s].getChildNode("ResourceBase").getStringValueEx();
ArrayList<String> welcomeFileList = new ArrayList<String>();
if (httpContextNodes[s].hasChildNode("WelcomeFile")) {
String welcomeFile = httpContextNodes[s].getChildNode("WelcomeFile").getStringValueEx();
welcomeFileList.add(welcomeFile);
}
ContextHandler context = new ContextHandler(contexts, urlPath);
ResourceHandler resourceHandler = new ResourceHandler();
resourceHandler.setResourceBase(resourceBase);
resourceHandler.setWelcomeFiles((String[]) welcomeFileList.toArray(new String[welcomeFileList.size()]));
context.setHandler(resourceHandler);
} catch (Exception ex) {
trace.warning("Configuration of http contexts failed", ex);
throw ex;
}
}
setResourceBase(resourceBase) 和 setWelcomeFiles((String[]) welcomeFileList.toArray(new String[welcomeFileList.size()]));
这是我找到 DefaultSERvlet 的同一个类中的另一个地方
ServletHolder holderDefault = new ServletHolder("default",DefaultServlet.class);
holderDefault.setInitParameter("dirAllowed","false");
并且已经在 web.xml 中定义
<servlet>
<servlet-name>default</servlet-name>
<servlet-class>org.eclipse.jetty.servlet.DefaultServlet</servlet-class>
<init-param>
<param-name>dirAllowed</param-name>
<param-value>false</param-value>
</init-param>
</servlet>
【问题讨论】:
-
在 Jetty 上,使用
DefaultServlet,而不是ResourceHandler来提供支持范围的静态内容。 -
谢谢@JoakimErdfelt;我在找到参考的地方添加了编辑,因此不确定在需要时在哪里进行更改
-
感谢帖子的链接。在进行范围请求时,我假设一旦您在数据服务器端处理了文件/流,它实际上需要以字节范围发送响应,并且码头不使用您指定的标头处理部分范围请求本身? Content-Range 等,基本上我是在询问流是否必须实际将字节范围返回给将其返回给 webclient 的 web 服务器。
标签: html google-chrome jetty