var $myVideo = $(".myVideo");
if ($myVideo.length) {
var index = 0;
// Videos managed by video.js
$.each($myVideo, function () {
var $this = $(this);
my.players.push(videojs($this.attr("id"), {controls: true}));
my.players[index].on("play", function () {
if (my.currentVideo !== null) {
my.currentVideo.pause();
}
my.currentVideo = this;
my.lastStartTime = new Date();
setTimeout(function () {
$this.addClass("started");
}, 500);
});
my.players[index].on("pause", function () {
if (!my.exitingSlide) {
if (my.currentVideo === this) {
my.currentVideo = null;
}
if ($this.hasClass("started")) {
my.trackVideoEvent(this);
}
}
});
my.players[index].on("ended", function () {
this.load();
$this.removeClass("started");
});
index++;
});
}
trackVideoEvent: function(player) {
var time = my.getSeconds(player),
clickdata = my.buildclickdata($("#"+player.id()), time);
if (clickdata === null) { return 0; }
var jsonString = JSON.stringify(clickdata);
com.gsk.mt.debug(jsonString);
var callback = function() { return 0; };
my.createRecord("Call_clickdata_vod__c", clickdata, callback);
},
getSeconds: function(video){
var seconds = 0;
video = $("#"+video.id()).find("video").get(0);
if (video.played.length > 1) {
for(var ii = 1; ii < video.played.length; ii++) {
seconds += video.played.end(ii) - video.played.start(ii);
}
} else if (video.played.length > 0) {
seconds += video.played.end(0) - video.played.start(0);
}
return Math.round(seconds);
},
我正在跟踪html5视频的持续时间。如果播放视频并暂停2秒,我将在控制台中使用2秒。再次,如果我在2秒恢复视频并播放接下来的3秒。我得到的使用时间是5秒而不是3秒。这是我的代码。我可以在每次暂停时将参数传递给getseconds并将其从完成时间中减去