查看: 51|回复: 0

html5 video标签播放视频流

[复制链接]

5

主题

0

回帖

0

积分

热心网友

金币
0
阅读权限
220
精华
0
威望
0
贡献
0
在线时间
0 小时
注册时间
2008-10-16
发表于 2019-8-21 17:39:00 | 显示全部楼层 |阅读模式

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

做了一个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>

 

回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

相关侵权、举报、投诉及建议等,请发 E-mail:qiongdian@foxmail.com

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版发帖返回顶部