{"id":2207,"date":"2010-12-14T10:47:36","date_gmt":"2010-12-14T05:17:36","guid":{"rendered":"http:\/\/www.tothenew.com\/blog\/?p=2207"},"modified":"2016-12-16T12:15:30","modified_gmt":"2016-12-16T06:45:30","slug":"using-custom-tag-for-embedding-the-video-in-grails","status":"publish","type":"post","link":"https:\/\/www.tothenew.com\/blog\/using-custom-tag-for-embedding-the-video-in-grails\/","title":{"rendered":"Using Custom Tag for embedding the Video in Grails"},"content":{"rendered":"<p><!-- pre.cjk { font-family: \"DejaVu Sans\",monospace; }p { margin-bottom: 0.08in; }a:link {  } -->I had to make a video available on my GSP page. So I looked at the <a href=\"http:\/\/www.grails.org\/plugin\/flash-player\" target=\"_blank\">grails flash-player plugin<\/a>.\u00a0\u00a0After going through the documentation I found that it could not be used with videos on YouTube.<\/p>\n<p>This code given below will generate the script for the flash player on your GSP for playing youtube videos.<\/p>\n<p>[html]<br \/>\n&lt;object width=&quot;480&quot; height=&quot;385&quot;&gt;<br \/>\n&lt;param name=&quot;movie&quot; value=&quot;http:\/\/www.youtube-nocookie.com\/v\/YG9RGKYauhE?fs=1&amp;amp;amp;hl=en_US&quot;&gt;<br \/>\n&lt;\/param&gt;<br \/>\n&lt;param name=&quot;allowFullScreen&quot; value=&quot;true&quot;&gt;&lt;\/param&gt;&lt;param name=&quot;allowscriptaccess&quot; value=&quot;always&quot;&gt;<br \/>\n&lt;\/param&gt;<br \/>\n&lt;embed src=&quot;http:\/\/www.youtube-nocookie.com\/v\/YG9RGKYauhE?fs=1&amp;amp;amp;hl=en_US&quot;<br \/>\ntype=&quot;application\/x-shockwave-flash&quot; allowscriptaccess=&quot;always&quot; allowfullscreen=&quot;true&quot; width=&quot;480&quot;<br \/>\nheight=&quot;385&quot;&gt;<br \/>\n&lt;\/embed&gt;&lt;\/object&gt;<br \/>\n[\/html]<\/p>\n<p>This is the general code for a YouTube video. URL in the browser for video looks like -http:\/\/www.youtube.com\/watch?v=<strong>YG9RGKYauhE<\/strong>&amp;feature=related.<\/p>\n<p>The common thing between embed code and URL of video is the<strong> key<\/strong> for the video which uniquely identifies it. So copy and paste the code in your GSP page and pass the video key to change the video as you want.<\/p>\n<p><strong>But to make it simple I made a custom tag like&#8211;<\/strong><\/p>\n<p>[groovy]<br \/>\ndef video={attrs-&gt;<br \/>\n        def videoKey=attrs[&#8216;videoKey&#8217;]<br \/>\n         def vd={<br \/>\n           object(width:attrs[&#8216;width&#8217;]?:&quot;640&quot;,height:attrs[&#8216;height&#8217;]?:&quot;385&quot;){<br \/>\n             param(name:&quot;movie&quot;,value:&quot;http:\/\/www.youtube-nocookie.com\/v\/${videoKey}?fs=1&amp;amp;amp;hl=en_US&quot;)<br \/>\n             param(name:&quot;allowFullScreen&quot;,value:&quot;true&quot;)<br \/>\n             param(name:&quot;allowscriptaccess&quot;,value:&quot;always&quot;)<br \/>\n             embed(src:&quot;http:\/\/www.youtube-nocookie.com\/v\/${videoKey}?fs=1&amp;amp;amp;hl=en_US&quot;,<br \/>\ntype:&quot;application\/x-shockwave-flash&quot;,allowscriptaccess:&quot;always&quot;,allowfullscreen:&quot;true&quot;,<br \/>\nwidth:&quot;${attrs[&#8216;width&#8217;]?:&#8217;640&#8242;}&quot;, height:&quot;${attrs[&#8216;height&#8217;]?:&#8217;385&#8242;}&quot;)<\/p>\n<p>           }<\/p>\n<p>         }<br \/>\n         def xml=new groovy.xml.StreamingMarkupBuilder().bind(vd)<br \/>\n         out&lt;&lt;xml<br \/>\n}<br \/>\n[\/groovy]<\/p>\n<p>so you just need to write the following tag which will set its default height, width etc.<\/p>\n<p>[html]&lt;my:image videoKey=\u201d&#8212;&#8212;-the key from youtube&#8212;&#8212;&#8212;\u201d \/&gt;[\/html]<\/p>\n<p>I hope\u00a0this helps!<\/p>\n<p><!-- p { margin-bottom: 0.08in; } --><\/p>\n","protected":false},"excerpt":{"rendered":"<p>I had to make a video available on my GSP page. So I looked at the grails flash-player plugin.\u00a0\u00a0After going through the documentation I found that it could not be used with videos on YouTube. This code given below will generate the script for the flash player on your GSP for playing youtube videos. [html] [&hellip;]<\/p>\n","protected":false},"author":27,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"iawp_total_views":3},"categories":[7],"tags":[4304,4840,4303],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/2207"}],"collection":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/users\/27"}],"replies":[{"embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/comments?post=2207"}],"version-history":[{"count":0,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/posts\/2207\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/media?parent=2207"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/categories?post=2207"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.tothenew.com\/blog\/wp-json\/wp\/v2\/tags?post=2207"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}