D
D
Denis Bukreev2016-09-23 23:10:21
YouTube
Denis Bukreev, 2016-09-23 23:10:21

YouTube API video playback not working - what to do?

So it goes.
HTML:

<div id="ytapiplayer">
  You need Flash player 8+ and JavaScript enabled to view this video.
</div>

JS:
const params = { allowScriptAccess: "always" };
    const atts = { id: "myytplayer" };
    swfobject.embedSWF("http://www.youtube.com/v/MQ3k6BFX2uw?enablejsapi=1&playerapiid=ytplayer&version=3",
        "ytapiplayer", "100%", "100%", "8", null, null, params, atts);

const onYouTubePlayerReady = playerId => {
    const ytplayer = document.getElementById("myytplayer");
    
    if (ytplayer) {
        console.log('before'); // выводится
        ytplayer.playVideo();
        console.log('after'); // не выводится
    }
};

And now, the preview video is shown. Click and watch.
But the API is not working.
There are no errors when calling playVideo(), the script just doesn't execute any further.
I read that it is necessary to upload to the server, otherwise it may not work - I posted it, Everything is the same there.
What to do? What is the hitch?
PS: and how to remove the muzzle of the pipe? I have my own interface for the video player

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
My joy, 2016-09-23
@t-alexashka

Maybe a jamb in http/https ?

O
Oleg, 2016-09-24
@politon

If you wang, then the question. Connected?

<script src="https://www.youtube.com/iframe_api"></script>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question