Skip to content

Commit

Permalink
Recorder resumes if start() is called in paused state (#1266)
Browse files Browse the repository at this point in the history
  • Loading branch information
rupel190 authored Feb 18, 2025
1 parent ab3c51c commit ead4f21
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 3 deletions.
13 changes: 13 additions & 0 deletions Tone/component/channel/Recorder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
9 changes: 6 additions & 3 deletions Tone/component/channel/Recorder.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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;
}

Expand Down

0 comments on commit ead4f21

Please sign in to comment.