使用其网址生成YouTube视频的嵌入代码 [英] generate youtube video's embed code using its url

查看:415
本文介绍了使用其网址生成YouTube视频的嵌入代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将YouTube视频添加到我的网站。我想知道,有没有办法通过生成 * '嵌入代码' * 'url' >(我们输入浏览器)作为输入



简单来说,是否有一种方法可以获取嵌入代码'作为输出视频的'url'作为输入吗?

我读了You​​tube的开发者API文档。它讨论了嵌入视频,但是,我无法找到任何有关'嵌入代码''视频网址'生成

我知道我可以在YouTube视频下的共享链接中手动复制嵌入代码。但我想用'video's url'来生成它,消除了人工努力的需要。



编辑:



有些视频被youtube屏蔽。那么,有没有办法在网站上显示这些视频?如果没有,是否有办法至少检测它是否被阻止?



例如 - * http://www.youtube.com/watch?v=aOWB0yGTrNY&list=PLZnxqowr6IKiDvDkEfptk0lcXuJqzn_dN 一>*。直接通过'iframe'中的'url'访问此链接不起作用。但是,如果我们在youtube上观看此视频并在iframe中使用其嵌入代码网址链接,那么它就可以工作。请帮我解决这个问题。

这将创建嵌入代码...然后您必须将其添加到body.or中或

函数

 函数yt(url){
return'< iframe width =420height =315src ='+ url +
'frameborder =0allowfullscreen>< / iframe>'
}

用法

  document.body.appendChild(document.createElement('div'))。innerHTML = yt('yturl') 

如果您有任何问题,请询问。

<这是不是最好的解决方案,但它是你问的。


编辑



某些视频被YouTube /用户屏蔽,您无法将其添加到您的页面。 btw所有视频都不能在其他iframe中工作。



您可以检查控制台中的原始错误。

EDIT2



视频是可嵌入的吗? 您需要使用api来检查

http://gdata.youtube.com/feeds/api/videos?v=2& ; alt = json& q = Main%20Tera%20Hero%20-%20Official%20Trailer%20(HD) $ b

我认为你正在搜索的是因为在这个标签内

  yt $ accessControl 


$ b

  app $ control 

您可以在这里阅读更多内容



https://stackoverflow.com/a/3937794/2450730



&& amp ;



<啊ref =http://apiblog.youtube.com/2011/12/understanding-playback-restrictions.html =nofollow noreferrer> http://apiblog.youtube.com/2011/12/understanding-playback- restrictions.html


I want to add youtube videos to my site. I want to know, is there a way to generate *'embed code'* by giving the 'url'(that we input into the browser) as input?

In simpler words, is there a way to get 'embed code' as output by giving the 'url' of the video as input?

I read the Youtube's developer API docs. It talks about embedding the video but, I couldn't find anything regarding generation of the 'embed code' from the 'video's url'

I know I can manually copy the 'embed code' from the share link under youtube's video. But I want to generate it using the 'video's url', removing the need of human effort in it.

Edit:

Some videos are blocked by youtube. So, is there a way to show those videos on the site? If not, is there a way to at least detect whether it is 'blocked or not'?

For ex. - *"http://www.youtube.com/watch?v=aOWB0yGTrNY&list=PLZnxqowr6IKiDvDkEfptk0lcXuJqzn_dN"*. This link when directly accessed through 'url' in an 'iframe' doesn't work. But if we go to this video on youtube and use its 'embed code url link' in an 'iframe', then it works. Please help me out with this.

解决方案

Embed youtube video

This creates the embed code... that you then have to append to the body.or wherever

Function

function yt(url){
return '<iframe width="420" height="315" src="'+url+
'" frameborder="0" allowfullscreen></iframe>'
}

Usage

document.body.appendChild(document.createElement('div')).innerHTML=yt('yturl')

if you have any questions just ask.

this is prolly not the best solution but it's what you asked.

EDIT

Some videos are blocked from youtube/user and you can't simply add them to you page. btw all videos don't work inside other iframes.

you can check the origin errors in your console.

EDIT2

Video is embeddable?

You need to use the api to check for that

http://gdata.youtube.com/feeds/api/videos?v=2&alt=json&q=Main%20Tera%20Hero%20-%20Official%20Trailer%20(HD)

i think that what you are searching for is inside this tags

yt$accessControl

or

app$control

you can read more here

https://stackoverflow.com/a/3937794/2450730

&&

http://apiblog.youtube.com/2011/12/understanding-playback-restrictions.html

这篇关于使用其网址生成YouTube视频的嵌入代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆