Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow recorder to resume when paused #1266

Merged
merged 1 commit into from
Feb 18, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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