Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface AudioLoader

Class for loading an AudioBuffer. This uses the FileLoader internally for loading files.

Code Example

// instantiate a listener
const audioListener = new THREE.AudioListener();
// add the listener to the camera
camera.add( audioListener );
// instantiate audio object
const oceanAmbientSound = new THREE.Audio( audioListener );
// add the audio object to the scene
scene.add( oceanAmbientSound );
// instantiate a loader
const loader = new THREE.AudioLoader();
// load a resource
loader.load(
'audio/ambient_ocean.ogg', // resource URL
function ( audioBuffer ) { // onLoad callback
// set the audio object buffer to the loaded object
oceanAmbientSound.setBuffer( audioBuffer );
// play the audio
oceanAmbientSound.play();
},
function ( xhr ) { // onProgress callback
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
},
function ( err ) { // onError callback
console.log( 'An error happened' );
}
);

Hierarchy

Index

Constructors

constructor

Properties

crossOrigin

crossOrigin: string

The crossOrigin string to implement CORS for loading the url from a different domain that allows CORS. Default is anonymous.

default

'anonymous'

manager

The loadingManager the loader is using. Default is DefaultLoadingManager.

path

path: string

The base path from which the asset will be loaded. Default is the empty string.

default

''

requestHeader

requestHeader: {}

The request header used in HTTP request. See .setRequestHeader. Default is empty object.

default

{}

Type declaration

  • [header: string]: string

resourcePath

resourcePath: string

The base path from which additional resources like textures will be loaded. Default is the empty string.

default

''

withCredentials

withCredentials: boolean

Whether the XMLHttpRequest uses credentials. See .setWithCredentials. Default is false.

default:

false

Methods

load

  • load(url: string, onLoad: (audioBuffer: AudioBuffer) => void, onProgress?: (request: ProgressEvent<EventTarget>) => void, onError?: (event: ErrorEvent) => void): void
  • Begin loading from url and pass the loaded AudioBuffer to onLoad.

    Parameters

    • url: string

      The path or URL to the file. This can also be a Data URI.

    • onLoad: (audioBuffer: AudioBuffer) => void

      Will be called when load completes. The argument will be the loaded text response.

        • (audioBuffer: AudioBuffer): void
        • Parameters

          • audioBuffer: AudioBuffer

          Returns void

    • Optional onProgress: (request: ProgressEvent<EventTarget>) => void

      Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .total and .loaded bytes. If the server does not set the Content-Length header; .total will be 0.

        • (request: ProgressEvent<EventTarget>): void
        • Parameters

          • request: ProgressEvent<EventTarget>

          Returns void

    • Optional onError: (event: ErrorEvent) => void

      Will be called when load errors.

        • (event: ErrorEvent): void
        • Parameters

          • event: ErrorEvent

          Returns void

    Returns void

loadAsync

  • loadAsync(url: string, onProgress?: (event: ProgressEvent<EventTarget>) => void): Promise<AudioBuffer>
  • Begin loading from url and pass the loaded AudioBuffer to onLoad.

    Parameters

    • url: string

      The path or URL to the file. This can also be a Data URI.

    • Optional onProgress: (event: ProgressEvent<EventTarget>) => void

      Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .total and .loaded bytes. If the server does not set the Content-Length header; .total will be 0.

        • (event: ProgressEvent<EventTarget>): void
        • Parameters

          • event: ProgressEvent<EventTarget>

          Returns void

    Returns Promise<AudioBuffer>

setCrossOrigin

setPath

setRequestHeader

setResourcePath

setWithCredentials

Generated using TypeDoc