Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 10 additions & 6 deletions docs/api/loaders/AudioLoader.html
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ <h1>[name]</h1>

<p class="desc">
Class for loading an
[link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer AudioBuffer].
This uses the [page:FileLoader] internally for loading files.
[link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer AudioBuffer]. <br/>
Unlike [page:FileLoader], [name] does not avoid multiple concurrent requests to the same URL.
</p>

<h2>Example</h2>
Expand Down Expand Up @@ -48,10 +48,8 @@ <h2>Example</h2>
oceanAmbientSound.play();
},

// onProgress callback
function ( xhr ) {
console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
},
// onProgress callback currently not supported
undefined,

// onError callback
function ( err ) {
Expand Down Expand Up @@ -92,6 +90,12 @@ <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Func
Begin loading from url and pass the loaded [page:String AudioBuffer] to onLoad.
</p>

<h3>[method:AudioLoader setPath]( [param:String path] )</h3>
<p>
Sets the base path or URL from which to load files. This can be useful if
you are loading many images from the same directory.
</p>

<h2>Source</h2>

[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
Expand Down
5 changes: 3 additions & 2 deletions docs/api/loaders/ImageBitmapLoader.html
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,9 @@
<h1>[name]</h1>

<p class="desc">
A loader for loading an [page:Image] as an [link:https://developer.mozilla.org/de/docs/Web/API/ImageBitmap ImageBitmap]. An ImageBitmap provides an asynchronous and resource efficient pathway to prepare textures for rendering in WebGL.

A loader for loading an [page:Image] as an [link:https://developer.mozilla.org/de/docs/Web/API/ImageBitmap ImageBitmap].
An ImageBitmap provides an asynchronous and resource efficient pathway to prepare textures for rendering in WebGL. <br/>
Unlike [page:FileLoader], [name] does not avoid multiple concurrent requests to the same URL.
</p>

<h2>Example</h2>
Expand Down
61 changes: 54 additions & 7 deletions src/loaders/AudioLoader.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { AudioContext } from '../audio/AudioContext.js';
import { FileLoader } from './FileLoader.js';
import { Cache } from './Cache.js';
import { DefaultLoadingManager } from './LoadingManager.js';

/**
* @author Reece Aaron Lecrivain / http://reecenotes.com/
* @author Mugen87 / https://github.com/Mugen87
*/

function AudioLoader( manager ) {
Expand All @@ -16,19 +17,65 @@ Object.assign( AudioLoader.prototype, {

load: function ( url, onLoad, onProgress, onError ) {

var loader = new FileLoader( this.manager );
loader.setResponseType( 'arraybuffer' );
loader.load( url, function ( buffer ) {
if ( url === undefined ) url = '';

if ( this.path !== undefined ) url = this.path + url;

url = this.manager.resolveURL( url );

var scope = this;

var cached = Cache.get( url );

if ( cached !== undefined ) {

scope.manager.itemStart( url );

setTimeout( function () {

if ( onLoad ) onLoad( cached );

scope.manager.itemEnd( url );

}, 0 );

return cached;

}

fetch( url ).then( function ( response ) {

return response.arrayBuffer();

} ).then( function ( arrayBuffer ) {

var context = AudioContext.getContext();

context.decodeAudioData( buffer, function ( audioBuffer ) {
context.decodeAudioData( arrayBuffer, function ( audioBuffer ) {

onLoad( audioBuffer );
Cache.add( url, audioBuffer );

if ( onLoad ) onLoad( audioBuffer );

scope.manager.itemEnd( url );

} );

}, onProgress, onError );
} ).catch( function ( error ) {

if ( onError ) onError( error );

scope.manager.itemEnd( url );
scope.manager.itemError( url );

} );

},

setPath: function ( value ) {

this.path = value;
return this;

}

Expand Down