0
我阅读了有关YouTube IFrame API的链接并做了一个包含HTML中iFrame的示例。Youtube IFrame api getVideoLoadedFraction()未在iOS中调用
我需要调用下面的函数:
player.getVideoLoadedFraction();
我使用下面的代码来创建播放器对象。
var player;
function onYouTubeIframeAPIReady()
{
alert('onYouTubeIframeAPIReady');
player = new YT.Player('player', {
height: '432',
width: '768',
videoId: 'tNpd9LCaG8',
events: {
'onReady': onPlayerReady,
'onStateChange': onPlayerStateChange
}
});
alert('player created');
}
和测试目的,我在onStateChange
事件添加player.getVideoLoadedFraction()
。
function onPlayerStateChange(event)
{
alert("onStateChange has fired!\nNew state:" + event.data);
var progress = player.getVideoLoadedFraction();
alert (progress);
}
该方法没有被调用。即使我在var progress = player.getVideoLoadedFraction();
这一行之后放置了任何警报,警报也不会显示。
任何人都可以帮助我解决这个问题。
谢谢
如果您查看https://developers.google.com/youtube/iframe_api_reference#Getting_Started,您可以看到他们在创建“YT.Player”对象时在'onYouTubeIframeAPIReady'内引用了这些函数。所以YouTube播放器了解它们。只是创建这些功能将不会将它们附加到'YouTube API'。编辑:您的第二个函数应该在之后调用,并且如果您在页面中包含API,则如文档中所述。 – thebreiflabb 2013-05-10 09:22:59
谢谢。添加了API代码。现在onYouTubeIframeAPIReady()被调用。但是player.getVideoLoadedFraction();没有被调用。我在哪里失踪? – Lara 2013-05-13 11:56:32