YouTube Player API: How to get duration of a loaded/cued video without playing it?

前端 未结 5 1120
你的背包
你的背包 2020-12-02 19:16

I\'m not able to get the correct video duration/length (in seconds) of a loaded/cued video via the getDuration() method of the YouTube Player API; the same method, however,

5条回答
  •  遥遥无期
    2020-12-02 20:07

    Solution 1

    You can use YouTube Data API to access most of the information about the video, including duration:

    
    
    

    Demo here

    When using jQuery you can use $.getJSON() to make things easier.

    Solution 2

    Seems like YouTube JavaScript API v3 allows you to get the correct duration inside the onYouTubePlayerReady() event. All you need to do is pass &version=3 when calling swfobject.embedSWF() method.

    Demo here

提交回复
热议问题