开发者

seekTo, playVideo, and pauseVideo functions not working in YouTube Player API

I'm working with the YouTube Player API and using the seekTo() function, but it doesn开发者_开发问答't work. In fact, playVideo() or pauseVideo() doesn't work too. Here is the code:

<script type="text/javascript" src="swfobject.js"></script>
<body>
<div id="divvideo">
<p>You will need Flash 8 or better to view this content.</p>
</div>
<script type="text/javascript">
    var params = { allowScriptAccess: "always" };
    var atts = { id: "video" };
    swfobject.embedSWF(
        "http://www.youtube.com/v/o3nmOw9vKw4?enablejsapi=1&playerapiid=video", "divvideo", "720", "405", "8", null, null, params, atts);

ytplayer = document.getElementById("video");

function play() {
    if (ytplayer) {
        ytplayer.playVideo();
    }

}
</script>
<a href="javascript:void(0);" onclick="play()">Play</a>
</body>

The video appears, but the Play hyperlink doesn't work. What should I do?


In your JavaScript, you have this:

ytplayer = document.getElementById("video");

But when you declare your element, you declare it like this:

<div id="divvideo">

See the mismatch? You're looking for an HTML element whose id is "video", but there isn't one -- your HTML element's id is "divvideo" instead.

You need to either change your getElementById call to take "divvideo", or else change your div to have id="video".

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜