Skip to main content

Class: WorkspaceAudio

Defined in: packages/blockly/core/workspace_audio.ts:29

Class for loading, storing, and playing audio for a workspace.

Methods index

MethodDescription
loadLoad an audio file. Cache it, ready for instantaneous playing.
playPlay a named sound at specified volume. If volume is not specified, use full volume (1).
beepPlays a beep at the given frequency.
playErrorBeepPlays a standard error beep.
setMuted-
getMutedReturns whether the audio is currently muted or not.

Constructors

Constructor

new WorkspaceAudio(parentWorkspace): WorkspaceAudio;

Defined in: packages/blockly/core/workspace_audio.ts:46

Parameters

ParameterTypeDescription
parentWorkspaceWorkspaceSvgThe parent of the workspace this audio object belongs to if it has one, or the workspace that owns this instance.

Returns

WorkspaceAudio

Methods

load()

load(filenames, name): Promise<void>;

Defined in: packages/blockly/core/workspace_audio.ts:69

Load an audio file. Cache it, ready for instantaneous playing.

Parameters

ParameterTypeDescription
filenamesstring[]Single-item array containing the URL for the sound file. Any items after the first item are ignored.
namestringName of sound.

Returns

Promise<void>


play()

play(name, opt_volume?): Promise<void>;

Defined in: packages/blockly/core/workspace_audio.ts:88

Play a named sound at specified volume. If volume is not specified, use full volume (1).

Parameters

ParameterTypeDescription
namestringName of sound.
opt_volume?numberVolume of sound (0-1).

Returns

Promise<void>


beep()

beep(tone, duration?): Promise<void>;

Defined in: packages/blockly/core/workspace_audio.ts:123

Plays a beep at the given frequency.

Parameters

ParameterTypeDefault valueDescription
tonenumberundefinedThe frequency of the beep to play, in hertz.
durationnumber0.2The duration of the beep, in seconds. Defaults to 0.2.

Returns

Promise<void>


playErrorBeep()

playErrorBeep(): Promise<void>;

Defined in: packages/blockly/core/workspace_audio.ts:152

Plays a standard error beep.

Returns

Promise<void>


setMuted()

setMuted(muted): void;

Defined in: packages/blockly/core/workspace_audio.ts:225

Parameters

ParameterTypeDescription
mutedbooleanIf true, mute sounds. Otherwise, play them.

Returns

void


getMuted()

getMuted(): boolean;

Defined in: packages/blockly/core/workspace_audio.ts:232

Returns

boolean

Whether the audio is currently muted or not.