Add simple play/pause controls

This commit is contained in:
Travis Ralston 2021-04-26 20:48:24 -06:00
parent e079f64a16
commit 30e120284d
9 changed files with 263 additions and 0 deletions

View file

@ -26,6 +26,7 @@ import {Singleflight} from "../utils/Singleflight";
import {PayloadEvent, WORKLET_NAME} from "./consts";
import {arrayFastClone} from "../utils/arrays";
import {UPDATE_EVENT} from "../stores/AsyncStore";
import {Playback} from "./Playback";
const CHANNELS = 1; // stereo isn't important
const SAMPLE_RATE = 48000; // 48khz is what WebRTC uses. 12khz is where we lose quality.
@ -270,6 +271,14 @@ export class VoiceRecording extends EventEmitter implements IDestroyable {
});
}
public getPlayback(): Promise<Playback> {
return Singleflight.for(this, "playback").do(async () => {
const playback = new Playback(this.buffer.buffer); // cast to ArrayBuffer proper
await playback.prepare();
return playback;
});
}
public destroy() {
// noinspection JSIgnoredPromiseFromCall - not concerned about stop() being called async here
this.stop();