NutzCN Logo
问答 用h5 audio播放mp3 播放一分钟就报错了
发布于 3092天前 作者 qq_6f395a53 2318 次浏览 复制 上一个帖子 下一个帖子
标签:

使用的时候 下载的是mp3 播放 用的是audio
```java
@At({"/", "/?"})
@Ok("raw")
@Fail("http:404")
@Filters
public Object image(String path, HttpServletResponse resp){
String filePath = "";
try{
byte[] img = path.getBytes();
filePath = new String(Base64.decode(img), "utf-8");
}catch(Exception e){
}
File file = new File(filePath);
if(file.exists()){
return file;
}else{
//输出[暂无图片]
return this.getClass().getResourceAsStream("/no_img.png");
}
}


```html <audio src="${base}/file/QzpcVXNlcnNcQWRtaW5pc3RyYXRvclxmaWxldXBsb2FkXDYwY2QwNTA0OWQ0NGI1NDQ5MmUxMWY3YmIwYWI5OWE4Lm1wMw==" controls="controls"></audio>

错误

java.lang.RuntimeException: org.apache.catalina.connector.ClientAbortException: java.io.IOException
	at org.nutz.lang.Lang.wrapThrow(Lang.java:153)
	at org.nutz.mvc.view.RawView.writeDownloadRange(RawView.java:317)
	at org.nutz.mvc.view.RawView.writeFileRange(RawView.java:326)
	at org.nutz.mvc.view.RawView.render(RawView.java:161)
	at org.nutz.mvc.impl.processor.ViewProcessor.process(ViewProcessor.java:66)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.MethodInvokeProcessor.process(MethodInvokeProcessor.java:28)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.AdaptorProcessor.process(AdaptorProcessor.java:33)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ActionFiltersProcessor.process(ActionFiltersProcessor.java:58)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.ModuleProcessor.process(ModuleProcessor.java:123)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.EncodingProcessor.process(EncodingProcessor.java:27)
	at org.nutz.mvc.impl.processor.AbstractProcessor.doNext(AbstractProcessor.java:44)
	at org.nutz.mvc.impl.processor.UpdateRequestAttributesProcessor.process(UpdateRequestAttributesProcessor.java:15)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:44)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:196)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2516)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2505)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.catalina.connector.ClientAbortException: java.io.IOException
	at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:407)
	at org.apache.tomcat.util.buf.ByteChunk.append(ByteChunk.java:342)
	at org.apache.catalina.connector.OutputBuffer.writeBytes(OutputBuffer.java:432)
	at org.apache.catalina.connector.OutputBuffer.write(OutputBuffer.java:420)
	at org.apache.catalina.connector.CoyoteOutputStream.write(CoyoteOutputStream.java:91)
	at org.nutz.mvc.view.RawView.writeDownloadRange(RawView.java:310)
	... 37 more
Caused by: java.io.IOException
	at org.apache.coyote.http11.InternalAprOutputBuffer.flushBuffer(InternalAprOutputBuffer.java:205)
	at org.apache.coyote.http11.InternalAprOutputBuffer.access$100(InternalAprOutputBuffer.java:37)
	at org.apache.coyote.http11.InternalAprOutputBuffer$SocketOutputBuffer.doWrite(InternalAprOutputBuffer.java:235)
	at org.apache.coyote.http11.filters.IdentityOutputFilter.doWrite(IdentityOutputFilter.java:84)
	at org.apache.coyote.http11.AbstractOutputBuffer.doWrite(AbstractOutputBuffer.java:192)
	at org.apache.coyote.Response.doWrite(Response.java:499)
	at org.apache.catalina.connector.OutputBuffer.realWriteBytes(OutputBuffer.java:402)
	... 42 more
七月 05, 2016 3:33:45 下午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [default] in context with path [] threw exception
java.lang.IllegalStateException: Cannot call sendError() after the response has been committed
	at org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:466)
	at org.nutz.mvc.view.HttpServerResponse.render(HttpServerResponse.java:181)
	at org.nutz.mvc.view.HttpStatusView.render(HttpStatusView.java:103)
	at org.nutz.mvc.impl.processor.ViewProcessor.process(ViewProcessor.java:66)
	at org.nutz.mvc.impl.processor.FailProcessor.process(FailProcessor.java:30)
	at org.nutz.mvc.impl.NutActionChain.doChain(NutActionChain.java:49)
	at org.nutz.mvc.impl.ActionInvoker.invoke(ActionInvoker.java:67)
	at org.nutz.mvc.ActionHandler.handle(ActionHandler.java:31)
	at org.nutz.mvc.NutFilter.doFilter(NutFilter.java:196)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.doRun(AprEndpoint.java:2516)
	at org.apache.tomcat.util.net.AprEndpoint$SocketProcessor.run(AprEndpoint.java:2505)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)
7 回复

这代码轻松被黑啊...

 File file = new File(filePath);

问题是,你这音频要播多久呢?是不是就1分钟呢???

音频长度是允许后台管理人员上传的,时长会有变动。普通MP3大概是4~6分左右,我这里播放大约1分钟左右会报java.io异常,我想处理这个 谢谢

我找个mp3播放试试

刚刚又测试下,发现MP3大约20秒左右,后台日志控制台输出【java.io.IOException】,但是前台MP3音频可以正常播放到最后

我测试了一下, 10分钟都没事, 音频的长度并没有关系. 按哪里播哪里.

至于为啥是60秒报错, 这个值恰好是nginx的默认proxy_read_time的默认值, 而audio标签是一直持有http连接,边播边读,并不是一次性读取完. 所以1分钟的时候, nginx发现timeout,断开连接了.

我项目还没有上线,也没有使用【nginx】,是个最简单的eclipse项目,大神 求demo 十分感谢

demo?

话说, 后台报错的话并不影响播放吧?

我测试的代码, 浏览器端跳转播放位置的话, 后台报错很正常, 因为提前断开连接了.

    @At("/play/mp3")
    @Ok("raw")
    public File play_mp3() {
        return new File("D:\\05472810ed6b26f5c90cc02d41e08865.mp3");
    }

页面

<div>
	<audio src="${base}/demo/play/mp3" controls="controls"></audio>
</div>
添加回复
请先登陆
回到顶部