Javascript 在seek事件完成时运行函数

Javascript 在seek事件完成时运行函数,javascript,vue.js,promise,dom-events,seek,Javascript,Vue.js,Promise,Dom Events,Seek,我有两个功能: async takeScreenShot() { this.pauseVideo(); if (this.animations.length && !this.ended) { this.pauseLotties() } this.captures.push(this.canvas.toDataURL('image/webp')); if (!this.ended) { setTimeout(() => { t

我有两个功能:

async takeScreenShot() {
  this.pauseVideo();
  if (this.animations.length && !this.ended) {
    this.pauseLotties()
  }
  this.captures.push(this.canvas.toDataURL('image/webp'));
  if (!this.ended) {
    setTimeout(() => {
      this.takeScreenShot();
    }, 500);
  }
},

async pauseVideo() {
  console.log("currentTime", this.video.currentTime);
  console.log("duration", this.video.duration);
  this.video.pause();
  const oneFrame = 1 / 30;
  if (this.video.currentTime + oneFrame < this.video.duration) {
    this.video.currentTime += oneFrame;
  } else {
    this.video.play()
  }
}
async takeScreenShot(){
这个。pauseVideo();
if(this.animations.length&&!this.end){
这是pauseLotties()
}
this.captures.push(this.canvas.toDataURL('image/webp');
如果(!this.end){
设置超时(()=>{
这个。截图();
}, 500);
}
},
异步pauseVideo(){
console.log(“currentTime”,this.video.currentTime);
console.log(“duration”,this.video.duration);
这个.video.pause();
const oneFrame=1/30;
if(this.video.currentTime+一帧
现在我正在使用
setTimeout
每500毫秒拍摄一次画布截图。但是我想使用seek事件截图,并承诺在搜索结束时让我知道,这样我就可以截图了。通过这种方式,它可以更高效、更快地翻录视频。我该怎么做呢

takeScreenShot(){
return new Promise((resolve,reject)=>{
    this.video.addEventListener("seeked", ()=>{
        return resolve()
    });
})
}

并使用

    this.takeScreenShot().then(()=>{
          return this.pauseVideo()
     }).then(()=>{
console.log("Successfull completed")
})

请告诉我这是否有用这是我想出的解决方案。虽然这并不是Sandeep Nagaraj所建议的,但他的评论确实在很大程度上帮助了我找到了解决方案。因此,我对他的职位投了更高的票

async takeScreenShot(){
  let seekResolve;
  this.video.addEventListener("seeked", async () => {
          if (seekResolve) seekResolve();
        });
await new Promise(async (resolve,reject)=>{
  console.log("promise running", this.video);
  if(!this.ended){
  if(this.animations.length){
    this.pauseLotties()
  }  
   this.pauseVideo();
  await new Promise(r => (seekResolve = r));
  this.layer.draw();
  this.captures.push(this.canvas.toDataURL('image/webp'));
  resolve()
  this.takeScreenShot()
    }
})
},