admin管理员组文章数量:1415071
I've been implementing the youtube API in my website, the playVideo()
for example works fine, so I guess there is nothing wrong with the implementation.. but the getDuration() gets an error (not such function error)
this is how I try to do it :
function GetDuration() {
var duration;
if (ytplayer) {
duration = ytplayer.getDuration();
}
$(".optionVideo").append("<p>" + duration + "</p>")
}
its error is that there is no such function. could anybody know what am I doing wrong ?
jsFiddle: /
I've been implementing the youtube API in my website, the playVideo()
for example works fine, so I guess there is nothing wrong with the implementation.. but the getDuration() gets an error (not such function error)
this is how I try to do it :
function GetDuration() {
var duration;
if (ytplayer) {
duration = ytplayer.getDuration();
}
$(".optionVideo").append("<p>" + duration + "</p>")
}
its error is that there is no such function. could anybody know what am I doing wrong ?
jsFiddle: http://jsfiddle/V36cL/6/
Share Improve this question edited Jun 25, 2012 at 17:32 gen_Eric 227k42 gold badges303 silver badges342 bronze badges asked Jun 25, 2012 at 16:56 thormayerthormayer 1,0706 gold badges29 silver badges49 bronze badges 5- 2 Example, jsFiddle? (Because according the Youtube API the function should exist.) – Styxxy Commented Jun 25, 2012 at 17:04
- Without the code as Styxxy suggests, we can't know for sure. Though looking just at this code, it could be that when this function is called, ytplayer is not fully initialized or it's the wrong object. – NateDSaint Commented Jun 25, 2012 at 17:07
-
1
@thormayer: Your jsFiddle has some errors. You forgot a
)
after$(document).ready(
. You forgot to include swfobject. You didn't have jQuery selected. Oh, andytplayer
is undefined. – gen_Eric Commented Jun 25, 2012 at 17:19 - @Rocket thanks, I've update it . jsfiddle/V36cL/3 – thormayer Commented Jun 25, 2012 at 17:28
- 1 @thormayer: Here's a better fiddle: jsfiddle/V36cL/6 :-P – gen_Eric Commented Jun 25, 2012 at 17:31
1 Answer
Reset to default 4You need to call GetDuration
from your onYouTubePlayerReady
, not from $(document).ready
. The YouTube video may be ready after the DOM is.
Also, your onYouTubePlayerReady
function needs to be global (jsFiddle wraps it in an anonymous function).
window.onYouTubePlayerReady = function(playerId) {
window.ytplayer = document.getElementById("ytPlayer");
GetDuration();
}
Demo: http://jsfiddle/V36cL/7/
本文标签: javascriptgetDuration() on youtube api is not a functionStack Overflow
版权声明:本文标题:javascript - getDuration() on youtube api is not a function? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745216646a2648201.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论