UNPKG

playcanvas

Version:

PlayCanvas WebGL game engine

34 lines (32 loc) 854 B
/** * Represents the resource of an audio asset. * * @category Sound */ class Sound { /** * Gets the duration of the sound. If the sound is not loaded it returns 0. * * @type {number} */ get duration() { var duration = 0; if (this.buffer) { duration = this.buffer.duration; } else if (this.audio) { duration = this.audio.duration; } return duration || 0; } /** * Create a new Sound instance. * * @param {HTMLAudioElement|AudioBuffer} resource - If the Web Audio API is supported, pass an * AudioBuffer object, otherwise an Audio object. */ constructor(resource){ if (resource instanceof Audio) { this.audio = resource; } else { this.buffer = resource; } } } export { Sound };