|
@@ -18,21 +18,41 @@ AudioLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
|
|
|
|
|
|
load: function ( url, onLoad, onProgress, onError ) {
|
|
load: function ( url, onLoad, onProgress, onError ) {
|
|
|
|
|
|
- var loader = new FileLoader( this.manager );
|
|
|
|
|
|
+ var scope = this;
|
|
|
|
+
|
|
|
|
+ var loader = new FileLoader( scope.manager );
|
|
loader.setResponseType( 'arraybuffer' );
|
|
loader.setResponseType( 'arraybuffer' );
|
|
- loader.setPath( this.path );
|
|
|
|
|
|
+ loader.setPath( scope.path );
|
|
loader.load( url, function ( buffer ) {
|
|
loader.load( url, function ( buffer ) {
|
|
|
|
|
|
- // Create a copy of the buffer. The `decodeAudioData` method
|
|
|
|
- // detaches the buffer when complete, preventing reuse.
|
|
|
|
- var bufferCopy = buffer.slice( 0 );
|
|
|
|
|
|
+ try {
|
|
|
|
+
|
|
|
|
+ // Create a copy of the buffer. The `decodeAudioData` method
|
|
|
|
+ // detaches the buffer when complete, preventing reuse.
|
|
|
|
+ var bufferCopy = buffer.slice( 0 );
|
|
|
|
+
|
|
|
|
+ var context = AudioContext.getContext();
|
|
|
|
+ context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
|
|
|
|
+
|
|
|
|
+ onLoad( audioBuffer );
|
|
|
|
+
|
|
|
|
+ } );
|
|
|
|
+
|
|
|
|
+ } catch ( e ) {
|
|
|
|
+
|
|
|
|
+ if ( onError ) {
|
|
|
|
+
|
|
|
|
+ onError( e );
|
|
|
|
+
|
|
|
|
+ } else {
|
|
|
|
+
|
|
|
|
+ console.error( e );
|
|
|
|
|
|
- var context = AudioContext.getContext();
|
|
|
|
- context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
|
|
|
|
|
|
+ }
|
|
|
|
|
|
- onLoad( audioBuffer );
|
|
|
|
|
|
+ scope.manager.itemError( url );
|
|
|
|
|
|
- } );
|
|
|
|
|
|
+ }
|
|
|
|
|
|
}, onProgress, onError );
|
|
}, onProgress, onError );
|
|
|
|
|