Primefaces p:media not showing youtube video - jsf-2

I have a primefaces p:media component
<p:media id="youTubeMedia" value="#{graffiticontroller.selectedYouTubeURL}" width="405" height="144" player="flash" />
the generated html is
<object height="144" width="405" data="http://www.youtube.com/watch?v=yY0PBoDlHMI" type="application/x-shockwave-flash">
the problem is that when the url is like http://www.youtube.com/watch?v=yY0PBoDlHMI , the youtube video does not show up . I just see a white box.
but if I alter the url to be http://www.youtube.com/v/yY0PBoDlHMI the video shows up.
Please help

I resolved it reading this post http://forum.primefaces.org/viewtopic.php?f=3&t=346
I copied the top link of my youtube video and applied some format.
For example if this is the original link of your video https://www.youtube.com/watch?v=fJ9rUzIMcZQ.
The first thing you need to do is to replace "watch?" by "/" also you have replace the following "=" by "/" at the end you append this text to your link:
&hl=en&fs=1&
At the end you will get a link like this:
https://www.youtube.com/v/fJ9rUzIMcZQ&hl=en&fs=1&
And now you can use your p:media
<p:media value="https://www.youtube.com/v/fJ9rUzIMcZQ&hl=en&fs=1&" width="600" height="" player="flash"/>

put url in this way http://www.youtube.com/watch/v/yY0PBoDlHMI It will work...

Related

Url.Content is not showing image in razor view

I have a model class Registration in which I have a photo property which is saving the URL of the photo, my photos are saved in the images folder onto the root.
Now when I am trying to show the images it is not showing the image I have cross verified that the image is present there.
I have tried <img src="#item.Photo" width="100" height="100" />
#*<img src="#item.Photo" width="100" height="100" />*#
also I have tried
<img src="#Url.Content(#item.Photo)" height="25px" width="50px" />
my path becomes /imges/previous theme.jpg even adding ~ in start it is still not showing the result, I have images folder onto the root and inside that I have previous theme.jpg file
It should show the result as image, even after removing the url.Content
<img src="#item.Photo" />
is also not working.
#Url.Content(#item.Photo) is likely the binary representation of your image. An img src= tag must contain a url to the image, not the binary representation of the image itself
i think you should press F12, in the console tab you can see your wrong path image, and you can fix the path base on it.
Razor has been changed a little with ASP.NET MVC 4 beta.No more #Url.Content.
Now, instead of
<img src="#Url.Content("~/path")">
you can use
<img src="~/path">
Kindly check what you are getting in the console. check the path is correct.

How to view a doc/pdf file in grails application?

I am a grails beginner, and finding a way to view the doc/pdf files in the view. I tried embedding the file but got no output for it. How can i view the file?
Assuming that you don't just want to link to some other file on your server (if you do, Rahul's answer is perfectly fine) then you may want to consider something like this in a controller:
def retrieveFile() {
File fileToReturn = new File("${params.filePath}")
String filename = "whatever your filename is"
byteOutput = fileToReturn.readBytes()
response.setHeader("Content-disposition", "attachment; filename=\"${filename}\"");
outputStream << byteOutput
}
Then link to that (g.createLink or whatever) with the appropriate file path.
Add <embed> or <object>tag in your gsp file
<embed> tag Example:
<embed src="http://example.com/your-file.pdf" width="800" height="500" type='application/pdf'>
<object> tag Example:
<object width="800" height="500" type="application/pdf" data="http://example.com/your-file.pdf">
<p>Insert your error message here, if the PDF cannot be displayed.</p>
</object>
Above code tested and working with chrome and Firefox.
Basically there are many solutions, where you can you third party plugins and or using <iframe>
Thanks, Hope it helps you

embed a YouTube video in an XPages repeat control

I'm looking to embed a YouTube video into an XPage, probably into a repeat control. I've looked around but can't find anything specific to XPages. I can create a link to open the YouTube video but that just moves them to YouTube but I don't want to leave my site.
Does someone have an example of how to do this.
Use the HTML <iframe>, <object> or <embed> tag to insert YouTube videos into your XPage repeat control.
Example:
<xp:repeat
id="repeat1"
rows="30"
var="video"
indexVar="number">
<xp:this.value><![CDATA[#{javascript:
[ "http://www.youtube.com/embed/XMoTb1iep48",
"http://www.youtube.com/embed/lvs3vpmEKHg",
"http://www.youtube.com/embed/63lYaeOJZOA",
"http://www.youtube.com/embed/6D6PzLSlEsQ"
]
}]]></xp:this.value>
<iframe
width="400"
height="250"
style="margin:2em"
src="#{video}"
frameborder="0"
allowfullscreen="allowfullscreen">
</iframe>
<xp:text
rendered="#{javascript:(number + 1) % 2 == 0}">
<br />
</xp:text>
</xp:repeat>
Make sure you use http://www.youtube.com/embed/YOUR_VIDEO_ID as URL.
A detailed description you can find here.
You need to follow instructions and put a short snippet anywhere in the XPage. Something like:
<iframe title="YouTube video player" class="youtube-player" type="text/html"
width="640" height="390" src="http://www.youtube.com/embed/-X2zNe3YFNM"
frameborder="0" allowFullScreen></iframe>
With too many rows in your repeat you can expect lots of iframe reloads on every refresh.

BBcode gem for ruby on rails (BB-ruby) - change default size of youtube video?

Pretty much as the titles says.
I'm using the BB-ruby gem for BBcodes and I've got a little problem with the [youtube] tag.
How can I change the default size of the embedded youtube video that the [youtube] tag renders from BB-ruby? It's really small now, so I need a way to resize it.
Seems like you can't pass options to the youtube tag, you probably need to override the method. See if the following works:
module BBRuby
##tags.merge('YouTube' => [
/\[youtube\](.*?)\?v=([\w\d\-]+).*\[\/youtube\]/im,
'<object width="320" height="265"><param name="movie" value="http://www.youtube.com/v/\2"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/\2" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="320" height="265"></embed></object>',
'Display a video from YouTube.com',
'[youtube]http://youtube.com/watch?v=E4Fbk52Mk1w[/youtube]',
:video])
end
And change the width and height in the above code.

How to upload vimeo videos using Media plugin (and not HTML option)

I'm working on Ruby on Rails 2.3.8 and the last version of rails tinyMCE plugin.
I would like users to have the ability of adding all kind of videos into the text editor. As it's now, they can add Youtube videos, and also they can upload them from their computer.
The problem is that Vimeo videos don't only create a common HTML <object> code, but they create an iframe for them, and if I try to import one of them using the Media plugin, I'll have to paste this video for example: http://vimeo.com/16430948, and it will generate the following HTML (which won't work):
<object width="100" height="100" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000">
<param value="http://vimeo.com/16430948" name="src"><embed width="100" height="100" type="application/x-shockwave-flash" src="http://vimeo.com/16430948">
</object>
While Vimeo videos need the following HTML for being displayed:
<p><iframe frameborder="0" height="225" src="http://player.vimeo.com/video/16430948" width="400"></iframe></p>
<p>
<object classid="clsid:d27cdb6e-ae6d-11cf-96b8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=6,0,40,0" height="100" width="100">
<param name="src" value="http://vimeo.com/16430948" /><embed src="http://vimeo.com/16430948" width="100" height="100" type="application/x-shockwave-flash"></embed>
</object>
Now, which is the difference between this two generated HTML? It's that the iframe is missing in the first code I've posted, so it doesn't work.
So, the question is: how do I add that iframe to the tinyMCE programmability so it's automatically added when a Vimeo video is embedded?
Well, you should write your own plugin (it is pretty simple) to check for changes the user made.
When a user entered a vimeo link you just grab the relevant content from the editor and put it into a new element (an iframe).
Your code should look something like this (you will have to modify it, but i am sure you will get the right direction):
// you may choose an other event to check for
ed.onChange.add(function(ed){
var body = ed.getBody();
// check for vimeo using jquery object
$(body).find('param').each(function(index, Element){
// vimeo adress is found in value
if (this.value.search('http://vimeo.com') == -1) return;
var node = this;
var iframe_not_parent = 1;
while(node.nodeName !== 'body'){
node = node.parentNode;
if (node.nodeName !== 'iframe'){
iframe_not_parent = 0;
break;
}
}
// ok, this vimeo thing is not inside an iframe - put it inside
if (iframe_not_parent){
with(document.getElementById(iframe_id).contentWindow){
var new_iframe = document.createElement("iframe");
this.parentNode.parentNode.append(new_iframe);
new_iframe.append(this.parentNode);
}
}
});
});

Resources