从 Grails 控制器渲染视频内容
毫无疑问又是一个愚蠢的新手问题!我在 Grails 控制器中有一个字节数组,其中包含视频文件(确切地说是 *.mp4 文件)的内容。我熟悉如何从 grails 控制器渲染 JSON、XML 和其他基本类型,但我找不到任何显示如何输出视频的示例。本质上我想做以下事情:
render bytes as MP4
我意识到我可能需要一个构造,例如:
render(text:"<xml>some xml</xml>",contentType:"video/mpeg",encoding:"UTF-8")
但我不清楚如何获取其中的字节数组。显然我不是渲染类似 html 内容的专家。我隐藏在库函数后面太久了!任何指向参考或示例的指针将不胜感激。
因此,如果它有助于将建议指向正确的方向,则视频中的字节来自我正在使用 jets3t 库读取的 S3 对象。
No doubt another silly newb question! I have a byte array in a Grails controller that contains the contents of a video file (an *.mp4 file to be exact). I am familiar with how to render JSON, XML and other basic types from a grails controller but I can't find any examples showing how to output video. In essence I want to do the following:
render bytes as MP4
I realize that I probably need a construct such as:
render(text:"<xml>some xml</xml>",contentType:"video/mpeg",encoding:"UTF-8")
but I'm not clear how I get the byte array in there.Obviously I am not an expert on rendering html-like content. I've been hiding behind library functions too long! Any pointers to a reference or example would be much appreciated.
So if it helps point the advice in the right direction, the bytes with the video are coming from an S3 object that I am reading with the jets3t library.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
那应该可以解决问题。
That should do the trick.
虽然当然可以从控制器提供视频,但如果您的目标只是在浏览器中呈现 QuickTime 视频,则可能有更简单的解决方案。在这种情况下,您可能希望尝试使用 FlashPlayer 插件,可通过以下命令使用:
后,您可以简单地将以下行插入到您的视图 GSP 中:
安装此播放器 使该插件与 Grails V2 一起使用只需花些功夫,但现在它已经就位,我意识到该插件帮助我避免了多少工作。如果您想了解更多信息,请访问 http://grails.org/FlashPlayer+Plugin
While it's certainly possible to serve video from a controller, there may be a much simpler solution if your goal is only to present QuickTime video from within the browser. In this case you might instead wish to try the FlashPlayer plug-in, available with the command:
Once you get this player installed, you can then simply insert the following lines into your view GSP:
It took a little fiddling to get the plug-in to work with Grails V2, but now that it's in place I realize how much work that plug-in helped me to avoid. If you want to learn more, visit http://grails.org/FlashPlayer+Plugin