'Play java video streaming with player

I want to steam live video using Java to a player (FlowPlayer, JW Player, etc)

I found an example but it is using java servlets:

Servlet code:

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()

Flow generated code:

<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>

Is it possible to use sockets instead of a servlet to provide the video?

Can someone provide me an example using java sockets or nio channels?

Thanks



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source