WebRTC 在创建点对点(P2P)的连接之前,会先通过信令服务器交换两端的 SDP 和 ICE Candidate,取两者的交集,决定最终的音视频参数、传输协议、NAT 打洞方式等信息。在完成媒体协
顺晟科技
2022-09-15 20:48:18
75
从文件服务器读取音视频文件,以流的方式传给前台,并能够播放视频。
做了一个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>
09
2022-11
09
2022-11
19
2022-10
19
2022-10
19
2022-10
19
2022-10