【aliplayer】阿里播放器的使用

【1】设置播放器上次播放进度,player里面要用同步,所以不能使用axios进行数据交互

  var getuid = this.$store.state.uid;
  var getcid = this.$store.state.cid;
      
  player = new Aliplayer({
      id: 'player-con',
      width: '100%',
      autoplay: true,
      height:'370px',
      vid:this.video_id,//先前拿到的vid
      playauth:this.playauth,//vid拿到以后 后台给的播放凭证
      controlBarVisibility: 'always',
      cover:this.cover,
      },function(player){
          console.log('播放器创建好了。')
          //  将视频的进度存在locatStorage中,若有则直接设置进度条在哪里
          var memory_time = localStorage.getItem('memory_time:'+getcid);
          console.log("memory_time==" ,memory_time)
          if (memory_time){
            console.log("设置播放进度条")
            player.seek(memory_time);
          }else{
              //过没有,则进行数据库查询
              var tmp = Date.parse( new Date() ).toString();
              tmp = tmp.substr(0,10);
              $.ajax({
                url:url,
                type:'post',
                async:false,
                data:{
                  method:'getPlaying',
                  code:tmp,
                  content:{
                    u_id:getuid,
                    v_id:getcid
                  }
                },
                success:function(result){
                console.log('进行了存储操作啊啊啊啊',result)
                result = JSON.parse(result)
                  memory_time = result.data.playing;
                    player.seek(memory_time);
                }
              })
          }

      });
      player.on('timeupdate',handleReady);
      function handleReady(){
          console.log("this.c_id==",getcid)
            localStorage.setItem('memory_time:'+getcid,player.getCurrentTime());
      }

​

【2】要是要切换视频,建议销毁后重新创建player

player.dispose();

再对播放器进行【1】中步骤初始化

你可能感兴趣的:(vue,前端,aliplayer,vue)