我想通過代理從Java服務器到Web應用程序的文件來解決跨域問題。這在大多數情況下都能正常工作,但在iOS中,視頻無法運行。Java服務文件到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基線-PRESET慢-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)
您已經實現了多少HTTP範圍請求規範?你能顯示產生你包含的日誌的代碼嗎? – duskwuff
感謝代碼是該鏈接。 – user5839
該代碼是用PHP編寫的,而不是Java編寫的。你在做什麼? – duskwuff