Youtube API playVideo does not work when running locally

Has anyone had an instance where onYouTubeplayerReady works, that is, the id is passed, but the object does not work?

Here is my code:

<div id="ytplayer"></div>
<script language="javascript">
var 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 view is correctly captured, but when I click "Play", it says that playVideo is not a function. I read earlier posts about an internet issue. My business is on the Intranet, so I assume everything should be fine? Please advise. Thank!

+3
source share
2 answers

It is written on the API page:

Getting started Note. To test any of these calls, you must have a file running on the web server, as Flash Player restricts calls between local files and the Internet.

+1

Source: https://habr.com/ru/post/1735892/


All Articles