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

feat: added seek & rate to SpeakerAudioDestination #504

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
32 changes: 18 additions & 14 deletions src/sdk/Audio/SpeakerAudioDestination.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ export class SpeakerAudioDestination implements IAudioDestination, IPlayer {
this.privId = audioDestinationId ? audioDestinationId : createNoDashGuid();
this.privIsPaused = false;
this.privIsClosed = false;
this.privAudio = new Audio();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The undefined value of privaAudio means the playback is not supported (e.g. unsupported format, see line 134). This would break some current logic. So pls revert.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@yulin-li can you please elaborate your response? From what I can see calling method format will re-initialize privAudio so it doesn't matter if I also set it constructor. I'm only trying to understand if there's a better approach than re-adding undefined checks (following null object pattern). Thanks.

}

public id(): string {
Expand Down Expand Up @@ -175,36 +176,39 @@ export class SpeakerAudioDestination implements IAudioDestination, IPlayer {
}

public get volume(): number {
return this.privAudio?.volume ?? -1;
return this.privAudio.volume;
}

public set volume(volume: number) {
if (!!this.privAudio) {
this.privAudio.volume = volume;
}
this.privAudio.volume = volume;
}

public get rate(): number {
return this.privAudio.playbackRate;
}

public set rate(speed: number) {
this.privAudio.playbackRate = speed;
}

public set seek(time: number) {
this.privAudio.currentTime = time;
}

public mute(): void {
if (!!this.privAudio) {
this.privAudio.muted = true;
}
this.privAudio.muted = true;
}

public unmute(): void {
if (!!this.privAudio) {
this.privAudio.muted = false;
}
this.privAudio.muted = false;
}

public get isClosed(): boolean {
return this.privIsClosed;
}

public get currentTime(): number {
if (this.privAudio !== undefined) {
return this.privAudio.currentTime;
}
return -1;
return this.privAudio.currentTime;
}

public pause(): void {
Expand Down