Recorder resumes if start() is called in paused state

This commit is contained in:
rupel 2024-08-02 03:00:35 +02:00
parent 3fee7e9976
commit 45718b17d9
2 changed files with 19 additions and 3 deletions

View file

@ -68,6 +68,19 @@ describe("Recorder", () => {
rec.dispose();
});
it("can be resumed after pausing", async () => {
const rec = new Recorder();
rec.start();
expect(rec.state).to.equal("started");
await wait(100);
rec.pause();
expect(rec.state).to.equal("paused");
await wait(100);
rec.start();
expect(rec.state).to.equal("started");
rec.dispose();
});
it("can be stopped after starting", async () => {
const rec = new Recorder();
rec.start();

View file

@ -107,7 +107,7 @@ export class Recorder extends ToneAudioNode<RecorderOptions> {
}
/**
* Start the Recorder. Returns a promise which resolves
* Start/Resume the Recorder. Returns a promise which resolves
* when the recorder has started.
*/
async start() {
@ -121,8 +121,11 @@ export class Recorder extends ToneAudioNode<RecorderOptions> {
this._recorder.addEventListener("start", handleStart, false);
});
this._recorder.start();
if(this.state === "stopped") {
this._recorder.start();
} else {
this._recorder.resume();
}
return await startPromise;
}