Getting Current YouTube Video Time

后端 未结 7 792
[愿得一人]
[愿得一人] 2020-11-28 08:27

I am writing a Browser Plugin and need to find a way to get the current time a YouTube Video playing on YouTube using JavaScript. I have been playing around in the Chrome Ja

相关标签:
7条回答
  • 2020-11-28 09:18

    Finally I found how to make it work on iOS (and Android too).
    Actually, the whole youtube js api was broken for me if run on mobile browser.

    Problem solved by creating player using new YT.Player as described in YouTube IFrame API.

    Please note: only creating <iframe> from <div> placeholder works for mobile browsers at the time. If you try to use existing <iframe> in new YT.Player call, as mentioned in IFrame API, this will not work.

    After player created, it's possible to use player.getCurrentTime() or player.getDuration() with player instance created.

    Note: I had no luck calling this methods on player obtained with
    player = document.getElementById(...) (from @JosephMarikle answer).
    Only created player instance worked in mobile browsers.


    Useful links:

    • YouTube IFrame API
    • YouTube JavaScript API
    • YouTube Player Demo
    0 讨论(0)
提交回复
热议问题