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

前端 未结 5 1127
你的背包
你的背包 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

    Using jQuery

    var youTubeURL = 'http://gdata.youtube.com/feeds/api/videos/oHg5SJYRHA0?v=2&alt=json';
    var json = (function () {
        $.ajax({
            'async': false,
            'global': false,
            'url': youTubeURL,
            'dataType': "jsonp", // necessary for IE9
            crossDomain: true,
            'success': function (data) {
                var duration = data.entry.media$group.yt$duration.seconds;
            }
        });
    })();
    

提交回复
热议问题