vinian 发表于 2022-4-27 21:58:54

【某干部学习网】求助分析一下

想写个脚本秒刷视频的。我感觉控制时长的代码应该在这里面,我是小白求大神帮助。

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['disablePictureInPicture']=true;//去掉画中画
    $("#" + player.player_id).bind("ended", function () {
      //player.play(curr);

      if(switchPlayList.length==1||curr >= switchPlayList.length){
            $("#"+player.player_id).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).readyState == 4;
}
player.play = function (stat) {
    if (typeof(stat) == "undefined"||"number") {
      //$("#"+player.player_id).play();
      videoPlay(stat);

    }else{
      $("#"+player.player_id).pause();
    }


};

function videoPlay(i){
       // $("#"+player.player_id).attr("src",switchPlayList.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.url);
      player.currentIndex=i;
      $("#"+player.player_id).load();//若视频很短,加载完后再播放,监听canplaythrough事件即可
      $("#"+player.player_id).play();

      //选中当前菜单
      var id = switchPlayList.id;
      $(".first_list li").removeClass("current");
      $(".first_list li").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).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 == "" || now_play == undefined) {
            now_play = 0;
      }
      player.setPosition(parseInt(now_play));
      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).networkState;
    var readyState = $("#"+player.player_id).readyState;
    if(netState == 0){
      return -1;
    }else if(!$("#"+player.player_id).paused){
      return 3;
    }else if($("#"+player.player_id).paused){
      return 4;
    }else if($("#"+player.player_id).paused&&$("#"+player.player_id).currentTime == $("#"+player.player_id).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).currentTime);
    else
      return 0;
};
player.setPosition = function (pos) {
    //if(player.realy())
      // $("#"+player.player_id).currentTime = pos;
    varvideo=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).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 == "" || now_play == undefined) {
      now_play = 0;
    }
    player.play(parseInt(now_play));
    //player.setPosition(now_play)
}*/



李恒道 发表于 2022-4-28 00:32:51

这种还是推荐哥哥学一下自己写...
别人即使看代码也没啥用的
页: [1]
查看完整版本: 【某干部学习网】求助分析一下