Display video content from a Grails controller

No doubt another stupid newb question! I have a byte array in the Grails controller that contains the contents of the video file (more precisely, the * .mp4 file). I am familiar with how to display JSON, XML and other basic types from a grails controller, but I cannot find examples showing how to output video. In essence, I want to do the following:

render bytes as MP4 

I understand that I probably need a construct like:

  render(text:"<xml>some xml</xml>",contentType:"video/mpeg",encoding:"UTF-8") 

but I do not understand how I can get an array of bytes. Obviously, I am not a specialist in rendering html-like content. I've been hiding behind library functions for too long! Any pointers to link or example would be highly appreciated.

So, if that helps point out the recommendations in the right direction, the bytes from the video come from the S3 object, which I read in the jets3t library.

+4
source share
2 answers
  OutputStream out = response.getOutputStream() //set up byte array byte[] content = yourS3Object.getBytes() response.setContentLength(content.size()) response.addHeader("Content-disposition", "attachment; filename=${yourS3Object.fileName}") response.addHeader("Content-type", "video/quicktime") out.write(content) out.close() 

That should do the trick.

+1
source

Although it may be possible to serve video from the controller, there may be a much simpler solution if your goal is to present QuickTime video only in a browser. In this case, instead, you can try the FlashPlayer plug-in , available with the command:

 grails install-plugin flash-player 

Once you install this player, you can simply insert the following lines into your GSP view:

 <div id="test"> <p>You need Flash Player installed to play this media.</p> </div> <g:flashPlayer id="test" varFile="${createLinkTo(dir: 'movies', file: 'my.mov')}"/> 

It took a little play to connect the plugin to Grails V2, but now that it is in place, I understand how much work this plugin helped me avoid. If you want to know more, visit http://grails.org/FlashPlayer+Plugin

+1
source

Source: https://habr.com/ru/post/1383195/


All Articles