playcanvas
Version:
PlayCanvas WebGL game engine
108 lines (107 loc) • 3.29 kB
TypeScript
/**
* @import { SoundManager } from '../sound/manager.js'
* @import { Sound } from '../sound/sound.js'
*/
/**
* A channel is created when the {@link SoundManager} begins playback of a {@link Sound}. Usually
* created internally by {@link SoundManager#playSound} or {@link SoundManager#playSound3d}.
* Developers usually won't have to create Channels manually.
*
* @ignore
*/
export class Channel {
/**
* Create a new Channel instance.
*
* @param {SoundManager} manager - The SoundManager instance.
* @param {Sound} sound - The sound to playback.
* @param {object} [options] - Optional options object.
* @param {number} [options.volume] - The playback volume, between 0 and 1. Defaults to 1.
* @param {number} [options.pitch] - The relative pitch. Defaults to 1 (plays at normal pitch).
* @param {boolean} [options.loop] - Whether the sound should loop when it reaches the
* end or not. Defaults to false.
*/
constructor(manager: SoundManager, sound: Sound, options?: {
volume?: number;
pitch?: number;
loop?: boolean;
});
volume: number;
loop: boolean;
pitch: number;
sound: Sound;
paused: boolean;
suspended: boolean;
manager: SoundManager;
/** @type {globalThis.Node | null} */
source: globalThis.Node | null;
startTime: number;
startOffset: number;
gain: GainNode;
/**
* Get the current value for the volume. Between 0 and 1.
*
* @returns {number} The volume of the channel.
*/
getVolume(): number;
/**
* Get the current looping state of the Channel.
*
* @returns {boolean} The loop property for the channel.
*/
getLoop(): boolean;
/**
* Enable/disable the loop property to make the sound restart from the beginning when it
* reaches the end.
*
* @param {boolean} loop - True to loop the sound, false otherwise.
*/
setLoop(loop: boolean): void;
/**
* Get the current pitch of the Channel.
*
* @returns {number} The pitch of the channel.
*/
getPitch(): number;
/**
* Handle the manager's 'volumechange' event.
*/
onManagerVolumeChange(): void;
/**
* Handle the manager's 'suspend' event.
*/
onManagerSuspend(): void;
/**
* Handle the manager's 'resume' event.
*/
onManagerResume(): void;
/**
* Begin playback of sound.
*/
play(): void;
/**
* Pause playback of sound. Call unpause() to resume playback from the same position.
*/
pause(): void;
/**
* Resume playback of the sound. Playback resumes at the point that the audio was paused.
*/
unpause(): void;
/**
* Stop playback of sound. Calling play() again will restart playback from the beginning of the
* sound.
*/
stop(): void;
/**
* Set the volume of playback between 0 and 1.
*
* @param {number} volume - The volume of the sound. Will be clamped between 0 and 1.
*/
setVolume(volume: number): void;
setPitch(pitch: any): void;
isPlaying(): boolean;
getDuration(): any;
_createSource(): void;
}
import type { Sound } from '../sound/sound.js';
import type { SoundManager } from '../sound/manager.js';