JS定时播放器

Posted Zard

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了JS定时播放器相关的知识,希望对你有一定的参考价值。

  public playerHandle = {
    state : false,
    animation : null,
    value : 0
  } 

 play(){
    if (!this.playerHandle.state){
      this.startAnimation();
    }else{
      this.stopAnimation();
    }
  }

  playNodeHandle(value){
    this.playerHandle.value = value;
    console.log(this.playerHandle.value)
  }

  startAnimation(){
    this.stopAnimation();
    this.playerHandle.state = true;
    this.playerHandle.animation = this.animate(this.playerHandle.value);
  }

  stopAnimation(){
    if (!this.playerHandle.animation) {
      return;
    }
    this.playerHandle.animation.remove();
    this.playerHandle.animation = null;
    this.playerHandle.state = false;
  }

  animate(startValue){
    var animating = true;
    var value = startValue;
    var frame : any = (timestamp)=> {
      if (!animating) {
        return;
      }
      value += 1
      if (value > 24) {
        value = 0;
        this.playerHandle.value = 0;
        this.stopAnimation();
        return undefined
      }
      this.playNodeHandle(value);
      setTimeout(function() {
        requestAnimationFrame(frame);
      }, 1000 );
    };
    frame();
    return {
      remove: function() {
        animating = false;
      }
    };
  }

以上是关于JS定时播放器的主要内容,如果未能解决你的问题,请参考以下文章

JS定时播放器

音乐播放制作(html css js)

asp.net c#如何编写学校体操定时音乐播放

JS控制视频的播放

使用 ffmpeg 生成单个 MPEG-Dash 片段

如何让 videoView 在片段内播放?