mirror of
https://github.com/google/blockly.git
synced 2026-01-11 10:57:07 +01:00
feat: add muted option (#7714)
* feat: add muted option * fix: linter * Update core/workspace_audio.ts Co-authored-by: Beka Westberg <bwestberg@google.com> * Update core/workspace_audio.ts Co-authored-by: Beka Westberg <bwestberg@google.com> * Update core/workspace_audio.ts Co-authored-by: Beka Westberg <bwestberg@google.com> * Update core/workspace_audio.ts Co-authored-by: Beka Westberg <bwestberg@google.com> --------- Co-authored-by: Beka Westberg <bwestberg@google.com>
This commit is contained in:
@@ -31,6 +31,9 @@ export class WorkspaceAudio {
|
||||
/** Time that the last sound was played. */
|
||||
private lastSound_: Date | null = null;
|
||||
|
||||
/** Whether the audio is muted or not. */
|
||||
private muted: boolean = false;
|
||||
|
||||
/**
|
||||
* @param parentWorkspace The parent of the workspace this audio object
|
||||
* belongs to, or null.
|
||||
@@ -121,6 +124,9 @@ export class WorkspaceAudio {
|
||||
* @param opt_volume Volume of sound (0-1).
|
||||
*/
|
||||
play(name: string, opt_volume?: number) {
|
||||
if (this.muted) {
|
||||
return;
|
||||
}
|
||||
const sound = this.sounds.get(name);
|
||||
if (sound) {
|
||||
// Don't play one sound on top of another.
|
||||
@@ -148,4 +154,18 @@ export class WorkspaceAudio {
|
||||
this.parentWorkspace.getAudioManager().play(name, opt_volume);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param muted If true, mute sounds. Otherwise, play them.
|
||||
*/
|
||||
setMuted(muted: boolean) {
|
||||
this.muted = muted;
|
||||
}
|
||||
|
||||
/**
|
||||
* @returns Whether the audio is currently muted or not.
|
||||
*/
|
||||
getMuted(): boolean {
|
||||
return this.muted;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user