我搜索了很多方法来获取访问我网站的用户的视频观看秒数。视频页面嵌入了 youtube 视频,我需要查看秒数才能在 Facebook 上发布。规则说:
如果该人观看了超过 50% 的视频,但没有完成,则应通过将 expires_in 更新为实际观看视频的时间长度来更新动作实例以反映该人已停止观看:http:// /developers.facebook.com/docs/opengraph/guides/video.watches/
到目前为止,我有以下即兴创作的代码。当用户按下开始视频时,我会启动一个计数器。问题在代码注释中。
function stopCycle(event) {
switch( event.data ) {
//event.data can be 1 or 2 . If user press play is event.data = 1 and if press
pause event.data = 2 and again if press play will be case 1. So each time
when user press START - PAUSE - CONTINUE - PAUSE event.data will have the value
case 1:
// here i post on facebook after 10 seconds as rules said
setTimeout('postwatch()', 10000);
//i get with ajax from youtube the video time (in seconds)
$.ajax({
url: "http://gdata.youtube.com/feeds/api/videos/<?php echo get_post_meta(get_the_ID(), 'tj_video_id_url', TRUE); ?>?alt=json",
dataType: "jsonp",
success: function (data) {
//here I appeal the ontimer function but the bug is that every tine i press play button even and after pause get appeal and the counter got crazy
onTimer(data.entry.media$group.yt$duration.seconds);
}
});
break;
}
console.log("onStateChange has fired!\nNew state:" );
}
i = 0;
function onTimer(videotime) {
document.getElementById('mycounter').innerHTML = i;
i++;
if (i > videotime) {
alert('Finish!');
}
else {
setTimeout(onTimer, 1000);
}
}
您知道任何替代方法或可以为我回答正确的方法吗?