我试图通过将文件从java服务器代理到Web应用来解决跨域问题。这在大多数情况下都可以正常工作,但在iOS中视频不会运行。
如果视频直接来自Amazon S3,它会运行,但如果我尝试从本地服务器运行它,我会得到' media_err_src_not_supported'错误。
我假设它与标题有关。我这样返回文件:
String filename = URLDecoder.decode(f, "UTF-8");
File file = new File("resources/files/", filename);
response.setHeader("Content-Type", "video/mp4");
response.setHeader("Content-Length", String.valueOf(file.length()));
response.setHeader("Content-Disposition", "inline; filename=\"" + file.getName() + "\"");
Files.copy(file.toPath(), response.getOutputStream());
尝试各种方法将视频文件放入视频元素,即
video.src = "/file/1.mp4";
或
video = document.createElement( 'video' );
source = document.createElement('source');
video.appendChild(source);
source.setAttribute('src',"/file/1.mp4");
source.setAttribute('type',"video/mp4");
视频在FFMPEG中编码
ffmpeg -i out.mp4 -vcodec libx264 -profile:v baseline -preset slow -pix_fmt yuv420p -b:v 5000k -maxrate 5000k -bufsize 2200k -s 1920:1080 -threads 0 -b:128k -movflags faststart out2K.mp4
如果来自S3,它将播放它,而不是来自我的服务器。
修改
我使用此MP4 plays when accessed directly, but not when read through PHP, on iOS
取得了一些进展浏览器中的错误相同,但服务器报告它正在发送浏览器请求的文件
34959 [qtp1121453612-40] INFO co.beek.pano.service.restService.MultipartFileSender - Return full file
35022 [qtp1121453612-37] INFO co.beek.pano.service.restService.MultipartFileSender - Return 1 part of file : from (0) to (15535447)
47812 [qtp1121453612-38] INFO co.beek.pano.service.restService.MultipartFileSender - Return full file
47971 [qtp1121453612-40] INFO co.beek.pano.service.restService.MultipartFileSender - Return 1 part of file : from (0) to (1)
47991 [qtp1121453612-39] INFO co.beek.pano.service.restService.MultipartFileSender - Return 1 part of file : from (0) to (16232853)
48380 [qtp1121453612-40] INFO co.beek.pano.service.restService.MultipartFileSender - Return 1 part of file : from (552544) to (16232853)
72467 [qtp1121453612-40] INFO co.beek.pano.service.restService.MultipartFileSender - Return 1 part of file : from (0) to (1)
72478 [qtp1121453612-39] INFO co.beek.pano.service.restService.MultipartFileSender - Return 1 part of file : from (0) to (15535447)
74094 [qtp1121453612-39] INFO co.beek.pano.service.restService.MultipartFileSender - Return 1 part of file : from (0) to (1)
74159 [qtp1121453612-51] INFO co.beek.pano.service.restService.MultipartFileSender - Return 1 part of file : from (0) to (15535447)
156335 [qtp1121453612-40] INFO co.beek.pano.service.restService.MultipartFileSender - Return 1 part of file : from (0) to (1)
156349 [qtp1121453612-57] INFO co.beek.pano.service.restService.MultipartFileSender - Return 1 part of file : from (0) to (15535447)
答案 0 :(得分:0)
手动设置内容类型
video = document.createElement( 'video' );
source = document.createElement('source');
video.appendChild(source);
source.setAttribute('src',"/file/1.mp4");
source.setAttribute('type',"video/mp4");
随着让这个多部分servlet工作修复它