在 clipChamp 压缩期间的 onVideoCreated 回调之前接收 "notify" 进度更新事件

Receiving "notify" progress update events before the onVideoCreated callback during clipChamp compression

我们正在使用 clipChamp API 来压缩我们用户的视频。我们使用 'direct input' 和 'blob output' 选项,以便我们的用户只与我们的 UI 而不是 clipChamp 的互动。

因为我们没有使用 clipChamp 的 UI,所以我们没有确定的进度条。 documentation 谈到在 onVideoCreated 回调上使用第三个参数通知回调,但这似乎根本没有做任何事情。

有人对此有经验吗?

onVideoCreated: function(blob: Blob, done: () => void, fail: () => void, notify: (percent: number) => void): any {

        notify(10);

        notify(30);

        notify(50);

        notify(90);

        notify(100);

        done();

}.bind(this)

// load options into the clipchamp inititalizer
this.clipChampProcess = clipchamp(clipChampOptions);

// inititalize clipchamp compression
this.clipChampProcess.open(clipChampOptions);

当使用不同的百分比值调用通知时,Clipchamp 小部件内的进度条应该反映出来。除了使用 done/fail/notify 回调,您还可以 return 来自 "onVideoCreated" 的承诺,例如 jQuery 的 Deferred。您的代码片段的等价物是:

onVideoCreated: function(blob) {
   var deferred = $.Deferred();

   deferred.notify(10);
   deferred.notify(30);
   deferred.notify(50);
   deferred.notify(90);
   deferred.notify(100);

   deferred.resolve();

   return deferred.promise();
}

在现实生活中,通知和解决(或拒绝)调用通常异步发生,例如反映上传传递给 "onVideoCreated" 的视频 blob 的进度、成功或失败。