公司建设网站价格,做网站运营工资多少,为您打造高端品牌网站,wordpress抽奖插件今天遇到了个神奇的问题#xff0c;视频文件在pc端和安卓手机上播放都没问题#xff0c;但是在ios上就是播放不了#xff0c;大概代码如下#xff1a;
前端代码#xff1a; video idvideo width350 height500 controlss…今天遇到了个神奇的问题视频文件在pc端和安卓手机上播放都没问题但是在ios上就是播放不了大概代码如下
前端代码 video idvideo width350 height500 controlssource src/getFileVideo typevideo/mp4/video后端代码 /*** description 获取视频文件** author yanzy* date 2022/12/16 17:37*/GetMapping(/getFileVideo)public void getFileVideo(HttpServletResponse response) throws IOException {File videoFile new File(E://test.mp4);FileInputStream inputStream new FileInputStream(videoFile);ServletOutputStream out response.getOutputStream();int byteRead 0;byte[] buffer new byte[1024];while ((byteRead inputStream.read(buffer)) ! -1) {out.write(buffer, 0, byteRead);}out.flush();inputStream.close();}PC端没任何问题 IOS端播放不了 在网上搜索了很多办法有加前端参数配置的 video idvideo width350 height500 controlsmuted autoplay preload loopx5-video-player-fullscreentruex5-playsinlineplaysinlinewebkit-playsinlinepostertest.jpgsource src/getFileVideo typevideo/mp4/video有改后端多次发送请求分段获取数据流的 经过多次测试最终找到了问题视频文件在ios上需要两个参数一个是视频文件的类型一个是文件的大小长度 response.setContentType(video/mp4);response.setHeader(Content-length, String.valueOf(videoFile.length()));修改后ios浏览器就可以正常播放了