YouTube Player API: retrieving a reference to an existing player

前端 未结 2 624
死守一世寂寞
死守一世寂寞 2020-12-20 10:21

I\'m developping a Google Chrome extension, using content script. I want to interact with pages embedding a YouTube video player. I have include the www-widgetapi-vflj

相关标签:
2条回答
  • 2020-12-20 10:33

    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.

    0 讨论(0)
  • 2020-12-20 10:51

    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.

    0 讨论(0)
提交回复
热议问题