我想使用 Java 将实时视频流式传输到播放器(FlowPlayer、JW Player 等)
我找到了一个示例,但它使用的是 java servlet:
小服务程序代码:
byte[] data = findingService.getVideo(params.id)
response.setContentType("video/avi")
response.setContentLength(data.length)
println "length=${data.length}"
byte[] content = new byte[1024];
BufferedInputStream is = new BufferedInputStream(new ByteArrayInputStream(data));
OutputStream os = response.getOutputStream();
while (is.read(content) != -1) {
println "... write bytes";
os.write(content);
}
is.close()
os.close()
流生成代码:
<a href="/finding/video.avi?id=99" style="display:block;width:215px;height:150px;" id="flowplayer_99">
<object width="100%" height="100%" id="flowplayer_99_api" name="flowplayer_99_api" data="/swf/flowplayer-3.2.4.swf?0.1476281308569014" type="application/x-shockwave-flash">
<param name="allowfullscreen" value="true">
<param name="allowscriptaccess" value="always">
<param name="quality" value="high">
<param name="cachebusting" value="true">
<param name="bgcolor" value="#000000">
<param name="flashvars" value="config={"playerId":"flowplayer_99","clip":{"url":"/finding/video.avi?id=99"},"playlist":[{"url":"/finding/video.avi?id=99"}]}">
</object>
</a>
是否可以使用套接字而不是 servlet 来提供视频?
有人可以为我提供一个使用 java 套接字或 nio 通道的示例吗?
谢谢