Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java servlet/grails如何正确地为Safari提供mp4文件?_Java_Servlets_Grails_Safari_Video Streaming - Fatal编程技术网

Java servlet/grails如何正确地为Safari提供mp4文件?

Java servlet/grails如何正确地为Safari提供mp4文件?,java,servlets,grails,safari,video-streaming,Java,Servlets,Grails,Safari,Video Streaming,在这个简单的代码中: def index() { def file = new File('/tmp/big_buck_bunny_720p_50mb.mp4') println "file = ${file} , length = ${file.length()}" if (file.exists()) { webRequest.renderView = false; response.setContentType("video/mp4")

在这个简单的代码中:

def index() {
    def file = new File('/tmp/big_buck_bunny_720p_50mb.mp4')
    println "file = ${file} , length = ${file.length()}"

    if (file.exists()) {
      webRequest.renderView = false;
      response.setContentType("video/mp4")
      response.setHeader("Content-disposition", "inline; filename=" + URLEncoder.encode(file.name, "UTF-8"));
      response.setHeader("Content-Length", String.valueOf(file.length()));

      InputStream is = new FileInputStream(file);

      response.outputStream << is
      response.outputStream.flush()
      response.outputStream.close()
      is.close()
    }
  } // index 
为什么该代码在Firefox中工作,但在Safari中已为此响应调用了断管getOutputStream()

如何修复它?谢谢

环境:Grails2.5.1

====更新=====

我发现这个问题:

,并且有一个URL

我的Safari可以成功播放视频

我试着模拟头部

$ curl -I http://techslides.com/demos/sample-videos/small.mp4
HTTP/1.1 200 OK
Server: nginx/1.4.1 (Ubuntu)
Date: Mon, 23 Nov 2015 04:25:36 GMT
Content-Type: video/mp4
Content-Length: 383631
Last-Modified: Sun, 16 Feb 2014 18:49:36 GMT
Connection: keep-alive
ETag: "53010840-5da8f"
Accept-Ranges: bytes
除ETag外,还插入了其他标头。
但Safari仍然无法播放,服务器报告了相同的异常。

对于任何对这个问题感兴趣(或陷入困境)的人,我已经找到了解决方案。这不是一个简单的解决方案

解决方案位于以下URL中:

它适用于servlet和Grails。

您好,在这个问题上:,我可以在safari中成功地播放mp4文件:。
$ curl -I http://techslides.com/demos/sample-videos/small.mp4
HTTP/1.1 200 OK
Server: nginx/1.4.1 (Ubuntu)
Date: Mon, 23 Nov 2015 04:25:36 GMT
Content-Type: video/mp4
Content-Length: 383631
Last-Modified: Sun, 16 Feb 2014 18:49:36 GMT
Connection: keep-alive
ETag: "53010840-5da8f"
Accept-Ranges: bytes