抓住youtube播放器的开始按钮和秒的看法
Catch the START button of youtube player and the seconds of view
我搜索了很多方法来获得访问我网站的用户观看视频的秒数。视频页面有嵌入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);
}
}
你知道有什么替代方法或能回答我一个正确的方法吗?
我做了这个替代,但我有一些延迟,当我点击暂停视频,定时器停止,但当我按下播放定时器已经开始与+ 1秒,但在视频我可能暂停在第4,5和我的定时器从5:
var started = 0;
function stopCycle(event) {
switch( event.data ) {
case 1:
ispaused = false;
if(started == 0) {
setTimeout('postwatch()', 10000);
onTimer(youtube.youtubeinfo.entry.media$group.yt$duration.seconds, 0);
started = 1;
}else if(started == 1) {
onTimer(youtube.youtubeinfo.entry.media$group.yt$duration.seconds, i);
}
break;
case 2:
setPause();
console.log('pauz');
break;
}
}
var ispaused=false;
function setPause(){
ispaused=!ispaused;
}
i = 0;
function onTimer(videotime, remaining) {
if(!ispaused) {
document.getElementById('mycounter').innerHTML = i;
if(remaining > 0) {
i = remaining;
console.log('ramas');
}
console.log(i);
if (i > videotime) {
alert('Finish!');
}else{
setTimeout(onTimer, 1000);
}
i++;
}
}
相关文章:
- 创建一个类似链接的按钮,并通过Javascript函数打开一个新的弹出窗口
- 正在添加'X'按钮,在文本字段旁边使用javascript
- 多个单选按钮组相互干扰
- JavaScript下拉菜单-点击按钮并根据所选值重定向到url
- Javascript按钮下拉列表
- jquery试图按名称获取按钮位置
- 漂亮照片图片库中的Facebook赞按钮
- 扩展移相器按钮类不工作
- 通过单击表单中的按钮,在代码生成中使用javascript生成字母数字代码
- 单击按钮以等待单击按钮
- 剑道UI内联编辑:如何在点击其他按钮时隐藏按钮
- 单击按钮后如何逐个调用分区,上一个分区将隐藏
- 如何从querySelectorAll中获取按钮类型
- 如何在输入字段中的按钮的帮助下打开日历,该字段的类型为“=”;日期”;
- 按下按钮时保存cookie
- 是否可以禁用jquery中的单个单选按钮
- ASP.NET通过单击JavaScript按钮触发c#事件
- 当我点击jsf中的primefaces命令按钮时,如何获得点击事件
- 点击按钮输入不起作用
- 抓住youtube播放器的开始按钮和秒的看法