AudioClip class
Play and manage an audio file.
Signature:
export declare class AudioClip extends ExternalObject implements ITimer
Extends: ExternalObject
Implements: ITimer
Remarks
Use AudioManager.load() to create an audio clip.
The constructor for this class is marked as internal. Third-party code should not call the constructor directly or create subclasses that extend the AudioClip
class.
Properties
Property | Modifiers | Type | Description |
---|---|---|---|
duration | readonly | number | The total length of the audio in seconds. |
loop | boolean | If true the audio player will automatically seek back to the start upon reaching the end of the audio and continue playing. | |
muted | boolean | Indicates whether the audio will be silenced or not. | |
playbackRate | number | Sets the rate at which the media is being played back. | |
playEnded | readonly | O3hEvent<[]> | Triggered when playback has reached the end of the audio file (and loop is false) |
volume | number | A number indicating the audio volume, from 0.0 (silent) to 1.0 (loudest) |
Methods
Method | Modifiers | Description |
---|---|---|
getTime() | Get the timing value of the timer | |
getTimeUpdates() | A more efficient way to get continuous updates of the timing value of the timer. | |
pause() | Pause playback of the audio, if the audio is already in a paused state this method will have no effect. | |
play() | Play the audio file. | |
reset() | Stop the timer and set it back to its original state, clearing it's time value. | |
resume() | Un-pauses the timer and start incrementing the time value again, can be called after the timer has been paused. | |
seek(time) | Sets the current playback position and seeks the loaded audio. | |
setSpeed(speed) | Control how quickly the timer increments. | |
start() | Start the timer from its initial state or after being reset. | |
stop() | Stop the timer, a call to reset is required before you can start it again. | |
unload() | Free the audio clip from memory. |
AudioClip.duration property
The total length of the audio in seconds.
Signature:
get duration(): number;
AudioClip.getTime() method
Get the timing value of the timer
Signature:
getTime(): Promise<number>;
Returns:
Promise<number>
A promise that resolves with the amount of time the timer has been running for in milliseconds
AudioClip.getTimeUpdates() method
A more efficient way to get continuous updates of the timing value of the timer.
Signature:
getTimeUpdates(): Subject<number>;
Returns:
Subject<number>
A subject triggered with the (number) value of ITimer.getTime() on every frame that it changes
AudioClip.loop property
If true the audio player will automatically seek back to the start upon reaching the end of the audio and continue playing.
Signature:
get loop(): boolean;
set loop(loop: boolean);
Remarks
This property is set to false for new audio clips created with AudioManager.load() (i.e. audio clips do not loop by default).
AudioClip.muted property
Indicates whether the audio will be silenced or not.
Signature:
get muted(): boolean;
set muted(muted: boolean);
AudioClip.pause() method
Pause playback of the audio, if the audio is already in a paused state this method will have no effect.
Signature:
pause(): void;
Returns:
void
AudioClip.play() method
Play the audio file.
Signature:
play(): Promise<void>;
Returns:
Promise<void>
A promise that resolves when the audio clip starts playing
AudioClip.playbackRate property
Sets the rate at which the media is being played back.
Signature:
get playbackRate(): number;
set playbackRate(playbackRate: number);
Remarks
Used to implement user controls for fast forward, slow motion, and so forth. The normal playback rate is multiplied by this value to obtain the current rate, so a value of 1.0 indicates normal speed.
AudioClip.playEnded property
Triggered when playback has reached the end of the audio file (and loop is false)
Signature:
get playEnded(): O3hEvent<[]>;
AudioClip.reset() method
Stop the timer and set it back to its original state, clearing it's time value.
Signature:
reset(): Promise<void>;
Returns:
Promise<void>
A promise that resolves when the operation is completed.
AudioClip.resume() method
Un-pauses the timer and start incrementing the time value again, can be called after the timer has been paused.
Signature:
resume(): void;
Returns:
void
AudioClip.seek() method
Sets the current playback position and seeks the loaded audio.
Signature:
seek(time: number): Promise<void>;
Parameters
Parameter | Type | Description |
---|---|---|
time | number | The play position in seconds |
Returns:
Promise<void>
A promise that resolves when the seek is complete
AudioClip.setSpeed() method
Control how quickly the timer increments.
Signature:
setSpeed(speed: number): void;
Parameters
Parameter | Type | Description |
---|---|---|
speed | number | A fraction of the normal speed of 1 |
Returns:
void
Remarks
Note that negative values will work, but currently the ReplayPlayer doesn't handle them.
AudioClip.start() method
Start the timer from its initial state or after being reset.
Signature:
start(): void;
Returns:
void
AudioClip.stop() method
Stop the timer, a call to reset is required before you can start it again.
Signature:
stop(): void;
Returns:
void
AudioClip.unload() method
Free the audio clip from memory.
Signature:
unload(): void;
Returns:
void
Remarks
Call this if you will not be using it again.
AudioClip.volume property
A number indicating the audio volume, from 0.0 (silent) to 1.0 (loudest)
Signature:
get volume(): number;
set volume(volume: number);
Updated 7 months ago