javascript html youtube 自定义播放按钮
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/9950801/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
html youtube custom play button
提问by Hymansonkr
The youtube player's play button works fine, but my custom play button does not work.
youtube 播放器的播放按钮工作正常,但我的自定义播放按钮不起作用。
** EDIT **
** 编辑 **
The current JSFiddlenow works fine on a pc/mac, but not on an iPad.
当前的 JSFiddle现在可以在 pc/mac 上正常运行,但不能在 iPad 上运行。
** EDIT 2 **
** 编辑 2 **
iframed youtube w/external play button
** EDIT 3 **
** 编辑 3 **
采纳答案by Hymansonkr
For whatever reason, limitations are in place. This does not work if you are on an ipad in html5. My jsfiddle does, however, work for desktop browsers.
无论出于何种原因,限制已经到位。如果您使用的是 html5 的 ipad,这将不起作用。但是,我的 jsfiddle 确实适用于桌面浏览器。
Please post back if you've gotten this to work for ipad and I'll re-mark you as the answer.
如果您已将其用于 ipad,请回帖,我会将您重新标记为答案。
回答by stewe
Try this:
试试这个:
however i would recommend to use something like swfobjectto embed the video.
但是我建议使用类似swfobject 的东西来嵌入视频。
https://developers.google.com/youtube/js_api_reference#Embedding
https://developers.google.com/youtube/js_api_reference#Embedding
回答by Sinan Samet
I just had this problem too I decided to give HTML5 a try and it worked. The only problem is that you will have to host the videos on your host.
我也遇到了这个问题,我决定尝试一下 HTML5,它奏效了。唯一的问题是您必须在主机上托管视频。
(Works on iPad) http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_video_js_prop
(适用于 iPad) http://www.w3schools.com/html/tryit.asp?filename=tryhtml5_video_js_prop
回答by shyam
Every Youtube embedded player contains a player id that is in the form of :
每个 YouTube 嵌入式播放器都包含一个播放器 ID,其格式为:
player_uid_\d+_1
like - player_uid_271874942_1
喜欢 - player_uid_271874942_1
So just do a regex search
for player_uid_\d+_1
in the page source
and add following js to anything you want :
所以,只是做了regex search
对player_uid_\d+_1
的page source
和下面的js添加到任何你想要的:
var player = document.getElementById(playerId);
//playerId id the matched string from regex search in page-source
player.playVideo();
Other actions related to above player variable can be found here.
可以在此处找到与上述玩家变量相关的其他操作。