开发者

Youtube API playVideo doesn't work when running locally

开发者 https://www.devze.com 2022-12-22 01:13 出处:网络
Anyone had instance where onYouTubeplayerReady works, i.e. id is passed, but the object isn\'t working?

Anyone had instance where onYouTubeplayerReady works, i.e. id is passed, but the object isn't working?

Here is my code:

<div id="ytplayer"></div>
<script language="javascript">
va开发者_C百科r vid;
function onYouTubePlayerReady(id) {
    vid = id;
}
        var currWidth = 320, currHeight = 265;
$("#ytplayer").html($.flash.create({
            "swf":"http://www.youtube.com/v/BA7fdSkp8ds?fs=1&enablejsapi=1&playerapiid=ytplayer",
            "width": currWidth,
            "height": currHeight,
            "params":{ allowScriptAccess: "always" }
                                }));
function play() {
    var vobj;
    if (vid) {
        vobj = document.getElementById(vid);
        vobj.playVideo();
    }
}
</script>
<div onClick="play()">Play</div>

The vid is correctly captured, but when I click "Play" it says playVideo is not a function. I've read earlier posts about Internet issue. My case is in Intranet so I assume it should be fine? Please advise. Thanks!


It's written on the API page:

Getting Started Note: To test any of these calls, you must have your file running on a webserver, as the Flash player restricts calls between local files and the internet.


I think that the intranet part is your problem, you need to upload the files to a web server. See http://code.google.com/apis/youtube/js_api_reference.html#GettingStarted

0

精彩评论

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

关注公众号