is there a rails library for taking embed code and returning the url of the video?
for example, if I pass the following:
<iframe width="420" height="315" src="//www.youtube.com/embed/J---aiyznGQ" frameborder="0" allowfullscreen></iframe>
it will return
www.youtube.com/embed/J---aiyznGQ
You can get the video id using a regular expression and then use that to generate the url.
Here is a good link for the regex: https://gist.github.com/afeld/1254889
Consider the following:
embed_code = '<iframe width="420" height="315" src="//www.youtube.com/embed/J---aiyznGQ" frameborder="0" allowfullscreen></iframe>'
regex = /(youtu\.be\/|youtube\.com\/(watch\?(.*&)?v=|(embed|v)\/))([^\?&"'>]+)/
youtube_id = embed_code.match(regex)[5]
'www.youtube.com/embed/' + youtube_id
#=> www.youtube.com/embed/J---aiyznGQ
Related
I was planning to do something like the following to embed a youtube video into a grav website using frontmatter (the page is currently using only only frontmatter with no entries in the markup file):
rows:
-
title: XYZ
description: 'Something'
description_position: left
image: image.JPG
name: video
-
title: IJK
description: 'Something'
description_position: right
html: '<iframe width="560" height="315" src="https://www.youtube.com/embed/somevideo" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen></iframe>'
This does not work. Grav does not say that this isn't valid frontmatter but it just doesn't create the iframe either. Is there a way to embed video from youtube using html inline in the frontmatter and without plugins?
They also have a dedicated youtube plugin (written by the grav developers) to better integrate into the markdown and frontmatter:
https://github.com/getgrav/grav-plugin-youtube
You can use the code below
<//iframe style="position:center;bottom:0px;left:0px;height:100%;width:100%" src="https://www.youtube.com/embed/-5wpm-gesOY" frameborder="0" allowfullscreen></iframe>
(// not use)
Good work
I am trying to get an embedded YouTube video to autoplay. I have set the ?autoplay=1 in the parameter but this seems to be deprecated. I have not been able to find any documentation on it though.
How can I get autoplay to work on videos?
<iframe class="iframe-vid" width="560" height="315" src="https://www.youtube.com/embed/Bey4XXJAqS8?autoplay=1&enablejsapi=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
If you don't mind that the video autoplays muted, you can add the following parameter in the YouTube URL:
&rel=0&mute=1
Here is the iframe with autoplay enabled and muted1
<iframe class="iframe-vid" width="560" height="315" src="https://www.youtube.com/embed/Bey4XXJAqS8?autoplay=1&enablejsapi=1&rel=0&mute=1" frameborder="0" allow="accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture" allowfullscreen=""></iframe>
Test made in Google Chrome Version 72.0.3626.119 (Build oficial) (32 bits)
1 I really don't know why the "mute" option must be set in the URL (and only in Google Chrome), because in Firefox and Edge the video autoplays without adding the mute parameter.
In order for the autoplay=1 to work, you must put the single quotation mark after the "1" and a space. Works perfect after.
ex. autoplay=1"
I have an old service working on frameset-frame (I know it's deprecated but I have no choice) and users can add youtube iframe tags.
but from some point the fullscreen action is not working anymore(it used to work).
There's allowfullscreen attribute added already.
<iframe width="560" height="315" src="https://www.youtube.com/embed/Ea9pOiwzd0c" frameborder="0" allowfullscreen></iframe>
I tried allowfullscreen on frameset and frame tag also.
I have tried like
allowfullscreen
allowfullscreen="true"
allowfullscreen="allowfullscreen"
mozallowfullscreen="mozallowfullscreen"
msallowfullscreen="msallowfullscreen"
oallowfullscreen="oallowfullscreen"
webkitallowfullscreen="webkitallowfullscreen"
... everything I can find on web but nothing worked for me.
You can try
allowfullscreen=true
I have tried to embed the video as shown below on my asp.net mvc app.
<div class="col-lg-12 center " data-animation="bounceInRight" data-delay="300">
<iframe width="170" height="128" ng-src="https://www.youtube.com/embed/watch?v=1aDLYFBuWc8" frameborder="0" allowfullscreen style="max-width:100%; margin:0 auto; display:block;"></iframe>
</div>
But when I tried to play, it shows below error.
There is no console window errors.When I tried to get the url by right clicking the above video then it shows this : https://youtu.be/undefined
But when I embeded below kind of url then it works fine.
https://www.youtube.com/embed/A6XUVjK9W4o
Could you tell me how to sort out this issue ? Thanks in advance.
Answer :
I think I can avoid this issue if I use the Video_Id as #Jossef Harush mentioned below.
Using ng-src in redundant
Since you don't dynamically set the video url in your example. no need to use ng-src
ng-src - http://plnkr.co/edit/HfJRVtt1Qga5UgyU242u?p=preview
src - http://plnkr.co/edit/LROnn8jHak1P8Hk4bR7e?p=preview
YouTube Embed URL is incorrect
from they're docs:
Embed a player using an tag
Define an tag in your application in which the src URL
specifies the content that the player will load as well as any other
player parameters you want to set. The tag's height and width
parameters specify the dimensions of the player.
If you create the element yourself (rather than using the
IFrame Player API to create it), you can append player parameters
directly to the end of the URL. The URL has the following format:
http://www.youtube.com/embed/VIDEO_ID
use https://www.youtube.com/embed/A6XUVjK9W4o
instead of https://www.youtube.com/embed/watch?v=1aDLYFBuWc8
Sample on Plunker
go to the wanted Youtube video and click on Share then you will get the option for a code snippet which you can embed into your code.
This is the default from yt
<iframe width="420" height="315" src="Link here" frameborder="0" allowfullscreen></iframe>
Bad url and you can't use ng-src try this:
<div class="col-lg-12 center " data-animation="bounceInRight" data-delay="300">
<iframe width="170" height="128" src="https://www.youtube.com/embed/1aDLYFBuWc8?rel=0" frameborder="0" allowfullscreen="" style="max-width:100%; margin:0 auto; display:block;"></iframe>
</div>
http://jsfiddle.net/6w3ao4ft/
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.