video control

function VideoControls(option){
this.id = option.videoId;
this.videoId = document.getElementsByTagName(option.videoId)[0];
this.prismplayer = option.prismplayer;
this.controls = $(".controls");
this.initData = {
playImage:"url('../../images/wx/experience/play.png')",
pauseImage:"url('../../images/wx/experience/pause.png')"
};
}
VideoControls.prototype = {
play:false,
allTime:"",
init:function(option){
this.allTimeFunction(option.time);
this.range();
this.click();
},
click:function(){
var self = this;
$("#playpausebtn").on("click",function(e){
e.stopPropagation();
self.playBtn($(this));
});
$("#fullscreenbtn").on("click",function(){
self.fullScreen();
});
},
timeIntel:function(time){
var mTime = Math.floor((time / 60));
var sTime = parseInt(time % 60);
var m = mTime > 9 ? mTime : "0" + mTime;
var s = sTime > 9 ? sTime : "0" + sTime;
return m + ":" + s;
},
currentTime:function(time){
$("#currentTime").html(this.timeIntel(time));
},
allTimeFunction:function(data){
var vallTime = data;
$("#allTime").html(this.timeIntel(vallTime));
this.allTime = vallTime;
},
range:function(time){
var self = this;
$("#seekslider").on("change",function(){
var val = ($(this).val() / 100) * self.allTime;
self.videoId.currentTime = val;
self.currentTime(val);
});
if(time){
$("#seekslider").val((time / self.allTime) * 100);
}
},
playBtn:function(self){
self = self || $("#playpausebtn");
var bgImg;

if(this.play){
bgImg = this.initData.playImage;
this.prismplayer.pause();
}else{
bgImg = this.initData.pauseImage;
this.prismplayer.play();
}

self.css({
"backgroundImage":bgImg
});

this.play = !this.play;
this.changeStatus();
},
changeStatus:function(){
var controls = this.controls;
controls.removeClass("controlshide");
setTimeout(function(){
controls.addClass("controlshide");
},1500);
},
fullScreen:function(){
    // moboile will bug , TODO
//$(this.id).removeAttr("webkit-playsinline").removeAttr("playsinline").attr("x5-video-player-fullscreen","true");
if(this.videoId.requestFullScreen){
alert(1)
this.videoId.requestFullScreen();
} else if(this.videoId.webkitRequestFullScreen){
alert(2)
this.videoId.webkitRequestFullScreen();
} else if(this.videoId.mozRequestFullScreen){
alert(3)
this.videoId.mozRequestFullScreen();
}else{
alert(0)
}
},
timeupdate:function(time){
this.currentTime(time);
this.range(time);
}
};
原文地址:https://www.cnblogs.com/founderswitch/p/7300315.html