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

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

问题描述

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

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?

简单来说,有没有办法通过将视频的 'url' 作为输入来获得 'embed code' 作为输出?

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

我阅读了 Youtube 的开发者 API 文档.它谈到了嵌入视频,但是,我找不到任何关于从 'vid​​eo's url'

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'

我知道我可以从 youtube 视频下的共享链接中手动复制嵌入代码".但我想使用视频的网址"生成它,从而无需人工操作.

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.

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

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'?

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

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.

推荐答案

嵌入 youtube 视频

这将创建嵌入代码...然后您必须将其附加到 body.or 任何地方

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

功能

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

用法

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.

编辑

有些视频被 youtube/user 屏蔽了,您不能简单地将它们添加到您的页面.顺便说一句,所有视频都不能在其他 iframe 中播放.

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

视频可以嵌入吗?

你需要使用api来检查

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(高清)

我认为您要搜索的内容在此标签内

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

yt$accessControl

app$control

你可以在这里阅读更多

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

&&

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

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

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