亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

在查找事件完成時運行函數

在查找事件完成時運行函數

開心每一天1111 2022-08-04 16:12:44
我有這兩個函數: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()  }}現在,我每500毫秒拍攝一次畫布的屏幕截圖。但我想使用seek事件截取屏幕截圖,并承諾在完成搜索時讓我知道,以便我可以截取屏幕截圖。這樣,它應該更有效地翻錄視頻,并可能更快。我該怎么做?setTimeout
查看完整描述

2 回答

?
慕的地8271018

TA貢獻1796條經驗 獲得超4個贊

takeScreenShot(){

return new Promise((resolve,reject)=>{

    this.video.addEventListener("seeked", ()=>{

        return resolve()

    });

})

}


并使用調用它


    this.takeScreenShot().then(()=>{

          return this.pauseVideo()

     }).then(()=>{

console.log("Successfull completed")

})

請看我知道這是否有幫助


查看完整回答
反對 回復 2022-08-04
?
慕標5832272

TA貢獻1966條經驗 獲得超4個贊

這就是我想出的解決方案。雖然這并不完全是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()

    }

})

},


查看完整回答
反對 回復 2022-08-04
  • 2 回答
  • 0 關注
  • 107 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號