zoukankan      html  css  js  c++  java
  • html5 video标签播放视频流

    从文件服务器读取音视频文件,以流的方式传给前台,并能够播放视频。

    做了一个demo,用html5的video,audio标签实现。

    后台实现代码:

    @GetMapping(value = "/getVideos")
    public String getVideos(HttpServletRequest request, HttpServletResponse response)
    {
        try {
            FileInputStream fis = null;
            OutputStream os = null ;
            fis = new FileInputStream("C:\Users\zhangxin\Desktop\douyin.mp4");
            int size = fis.available(); // 得到文件大小
            byte data[] = new byte[size];
            fis.read(data); // 读数据
            fis.close();
            fis = null;
            response.setContentType("video/mp4"); // 设置返回的文件类型
            os = response.getOutputStream();
            os.write(data);
            os.flush();
            os.close();
            os = null;
     
     
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }
        return null;
    }

    前端实现代码:

    <video width="1120" height="540" controls="controls" id="video" preload="auto"     >
        <source src="getVideos"   type="video/mp4">
    </video>
  • 相关阅读:
    HTML5之dir属性
    IPv4地址分类及子网划分
    二叉树的3种遍历
    js的点表示法和方括号表示法
    javascript-数组的常用方法
    第一编博文——漫长编程路
    使用qemu
    initial ram disk
    qemu常见选项解析
    cp和scp
  • 原文地址:https://www.cnblogs.com/vaevvaev/p/11390128.html
Copyright © 2011-2022 走看看