YouTube的JavaScript API第播放/暂停/停止不工作 [英] Youtube Javascript API Play/Pause/Stop not working

查看:772
本文介绍了YouTube的JavaScript API第播放/暂停/停止不工作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些麻烦用YouTube API。目前,我只是想有视频旁边的一个播放按钮。我运行(而不是在我的硬盘驱动器)上的本地Web服务器的code和我在网上搜索无果的多个主题。这里有一个演示中,我的另一个话题计算器看到,这理论上应该工作(和它的code我想目前使用)的 http://jsfiddle.net/L8qMe/1/
然而,在Firefox 15和IE浏览器在Windows 7上,播放按钮不为我在演示工作,所以我不再觉得这是一个code问题。它是一个安全设置可能?有没有办法解决它?请帮助!

I'm having some trouble with the Youtube API. Currently I'm simply trying to have a "play" button next to a video. I'm running the code on a local webserver (not on my hard drive) and I've searched multiple topics on the internet to no avail. Here's a demo I saw on another stackoverflow topic, which should theoretically work (and it's the code I'm trying to use currently): http://jsfiddle.net/L8qMe/1/ However, in Firefox 15 and IE on Windows 7, the play button does not work for me in the demo, so I no longer think this is a code problem. Is it a security setting maybe? Is there a way around it? Please help!

更新:无论是演示,也没有我的网络服务器(运行演示的code)在谷歌浏览器可以工作

Update: neither the demo nor my webserver (running the demo's code) works in google chrome either.

推荐答案

您需要添加事件监听器:

You need to add event listeners:

function onYouTubePlayerReady(playerId) { 
    ytplayer = document.getElementById("myytplayer");
    ytplayer.addEventListener("onStateChange", "onytplayerStateChange"); 
    ytplayer.addEventListener("onError", "onPlayerError"); 
}

的jsfiddle

这篇关于YouTube的JavaScript API第播放/暂停/停止不工作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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