想写个脚本秒刷视频的。我感觉控制时长的代码应该在这里面,我是小白求大神帮助。
if (typeof(player) == "undefined")
player = new Object();
player.player_time = 0;
player.hide = 0;
player.src;
player.duration;
player.currentIndex = 0;
player.otherClips=true;
player.init = function () {
player.switchClarity(player.clarity_id);
var video=$("#" + player.player_id);
video[0]['disablePictureInPicture']=true;//去掉画中画
$("#" + player.player_id).bind("ended", function () {
//player.play(curr);
if(switchPlayList.length==1||curr >= switchPlayList.length){
$("#"+player.player_id)[0].pause();
}else{
player.play(curr);
}
})
};
setInterval(function(){
if(player.getState()==3)
player.player_time++;
},1000);
player.getSrc = function(){
return player.src;
}
player.setSrc = function(src){
player.src = src;
}
player.realy = function(){
return $("#"+player.player_id)[0].readyState == 4;
}
player.play = function (stat) {
if (typeof(stat) == "undefined"||"number") {
//$("#"+player.player_id)[0].play();
videoPlay(stat);
}else{
$("#"+player.player_id)[0].pause();
}
};
function videoPlay(i){
// $("#"+player.player_id).attr("src",switchPlayList[i].url);
if($("#course_player")){
var videoTag="<video id='course_player' width='640px' height='360px' controls='controls' controlsList='nodownload' preload='preload' oncontextmenu='return false;'>"+
"\u60a8\u7684\u6d4f\u89c8\u5668\u7248\u672c\u8fc7\u4f4e\uff0c\u8bf7\u4f7f\u7528\u0049\u0045\u0039\u4ee5\u4e0a\u6216\u8005\u652f\u6301\u0048\u0054\u004d\u004c\u0035\u7684\u6d4f\u89c8\u5668\u3002</video>";
$("#video_box").empty();
}
$("#video_box").append(videoTag);
player.init();
$("#"+player.player_id).attr("src",switchPlayList[i].url);
player.currentIndex=i;
$("#"+player.player_id)[0].load();//若视频很短,加载完后再播放,监听canplaythrough事件即可
$("#"+player.player_id)[0].play();
//选中当前菜单
var id = switchPlayList[i].id;
$(".first_list li").removeClass("current");
$(".first_list li[id='" + id + "']").addClass("current");
$(".first_list>li").find("b").css("background", "url(imgs/chapter.png) no-repeat").parent("li.current").find("b").css("background", "url(imgs/chapter_active.png) no-repeat");
if (i< switchPlayList.length) {
i++;
}else{
i=0;
$("#"+player.player_id)[0].pause();
}
curr=i;
//切换清晰度时从播放点续播
if(claritySwitch){
player.setPosition(switchClipTime);
claritySwitch = false;
}
//从断点处继续播放
if (player.otherClips) {
var now_clip = breakPoint();
var now_play = now_clip.split(".");
if (now_play[0] == "" || now_play[0] == undefined) {
now_play[0] = 0;
}
player.setPosition(parseInt(now_play[0]));
player.otherClips = false;
}
}
player.switchClarity=function (i){
switch(i){
case 1:
switchPlayList =chapter.playlistH;
break;
case 2:
switchPlayList =chapter.playlistM;
break;
case 3:
switchPlayList =chapter.playlistL;
break;
}
return switchPlayList;
};
player.stop = function (stat) {
if(player.realy()){
player.setPosition(0);
player.play(false);
}
};
player.getState = function () {
var netState = $("#"+player.player_id)[0].networkState;
var readyState = $("#"+player.player_id)[0].readyState;
if(netState == 0){
return -1;
}else if(!$("#"+player.player_id)[0].paused){
return 3;
}else if($("#"+player.player_id)[0].paused){
return 4;
}else if($("#"+player.player_id)[0].paused&&$("#"+player.player_id)[0].currentTime == $("#"+player.player_id)[0].duration){
return 5;
}else if(netState == 1){
return 0;
}else if(netState == 3){
return 1;
}else if(netState == 2){
return 2;
}
};
player.getPosition = function () {
if(player.realy())
return Math.floor($("#"+player.player_id)[0].currentTime);
else
return 0;
};
player.setPosition = function (pos) {
//if(player.realy())
// $("#"+player.player_id)[0].currentTime = pos;
var video=document.getElementById(player.player_id);
video.addEventListener('loadedmetadata', function () {
video.currentTime = pos;
});
};
player.getRealTime = function () {
return player.player_time;
};
player.getDuration = function(){
//data.xml中定义的duration 与 真实视频的duration对比,取比较小的时长
var duration = Math.floor($("#"+player.player_id)[0].duration);
/if (duration!=null&&duration>0&&duration<player.duration) {
return duration;
}/
return player.duration;
};
/player.continuePlay=function(){
var now_clip = pos;//breakPoint();
var now_play = now_clip.split(".");
if (now_play[0] == "" || now_play[0] == undefined) {
now_play[0] = 0;
}
player.play(parseInt(now_play[1]));
//player.setPosition(now_play[0])
}/