YouTube Player API: retrieving a reference to an existing player

寵の児 提交于 2019-11-29 13:08:17
ek_

I was using YouTube player API before and it was working properly. Today I have issues like you, and I did not change anything in my code. It might mean that the www-widgetapi-vfljlXsRD.js has been changed and encounters bugs... I cannot help any further.

arnaud.breton

Ok, I found my way to talk to an existing player. I have not actually managed to get a working reference to it.

I was inspired by the amazing work of Rob (cf. YouTube iframe API: how do I control a iframe player that's already in the HTML?), I remarked that the Youtube player is sending message to the main window, like this:

{"event":"infoDelivery","info":{"currentTime":3.3950459957122803,"videoBytesLoaded":244,"videoLoadedFraction":0.24482703466872344},"id":1}

You can observe it by listening to the "message" event window.addEventListener('message', function (event) {console.log(event.data)}, false); in a window containing a playing player.

This infoDelivery event contains the current player's time and is sent while the video is playing. Listening to this event I am now able to know the current player time.

I have not found a proper solution so far so this one will make the job for the moment.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!