clearInterval为什么无效?

play(state,event){
  const playerBar=document.getElementById("playerBar");
  const eve=event.target;
  let duraTime=playerBar.duration;
  let duraMinute=Math.floor(duraTime/60)+":"+(duraTime%60/100).toFixed(2).slice(-2);
  let currentTime=playerBar.currentTime;
  let currentMinute=Math.floor(currentTime/60)+":"+(currentTime%60/100).toFixed(2).slice(-2);
  let ctime;
  if(playerBar.paused){
    playerBar.play();
    eve.innerHTML="pause";
    state.audio.duration=duraMinute;
    state.audio.currentTime=currentMinute;
    ctime=setInterval(
      function(){
        duraTime--;
        currentTime++;
        duraMinute=Math.floor(duraTime/60)+":"+(duraTime%60/100).toFixed(2).slice(-2);
        currentMinute=Math.floor(currentTime/60)+":"+(currentTime%60/100).toFixed(2).slice(-2);
        state.audio.duration=duraMinute;
        state.audio.currentTime=currentMinute;
     },1000
    )
  }else{
    playerBar.pause();
    eve.innerHTML="play_arrow";
    clearInterval(ctime);
  }
}

play()绑定的是一个播放器的开关,,点击一次时间会动,用的是定时器setInterval,再次点击清除计时器,时间暂停,用了clearInterval,但是目前clearInterval失效,不知道什么原因,拜托大神帮看看!!

WE2008311
浏览 2384回答 1
1回答

橋本奈奈未

你每次执行函数就把ctime初始化了,你应该定义在外层
打开App,查看更多内容
随时随地看视频慕课网APP