前端获取视频流并播放

前端获取视频流并播放

html5出来后,前端播放视频瞬间变得方便容易多了,一个<video>标签就可以搞定,只要给src属性正确的文件路径即可。

<video src="images/xxx.mov" width="300px" heigth="300px" controls="controls" autoplay></video>

但是当视频在服务器中时,就需要从后台向前台传输视频流才可以播放。

JAVA

@RequestMapping(value ="/getFileSrc" ,method = RequestMethod.GET)
@ResponseBody
public void getFileSrc(HttpServletRequest request ,HttpServletResponse response,@RequestParam(value="path") String path) throws IOException{
    File file = new File(path);
    FileInputStream input = new FileInputStream(file);
    int i = input.available();
    byte[] bytes = new byte[i];
    input.read(bytes);
    response.setContentType("application/video");
    OutputStream output = response.getOutputStream();
    output.write(bytes);
    output.flush();
    output.close();
    input.close();        
}

JS

var path1= "http://localhost:8080/HBDK/rest/resource/getFileSrc?path="+path;

<!--弹出框中播放-->
back.view.popup.open({
          title: "视屏播放",
          content:'<video src='+path1+' width="300px" heigth="300px" controls="controls" autoplay></video>',
          location: point // Set the location of the popup to the clicked location
    });

0ab9c431dada0876c833bcb51f641a78.png

本文标题:前端获取视频流并播放

文章作者:chen

发布时间:2017-09-05, 14:32:49

最后更新:2017-09-05, 14:45:29

原始链接:http://chen1218chen.github.io/2017/09/05/前端获取视频流并播放/

许可协议: “署名-非商用-相同方式共享 4.0” 转载请保留原文链接及作者。

  • 3
    点赞
  • 41
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值