diff --git a/src/audio/Audio.js b/src/audio/Audio.js index 521bb69ea9065234fcba75785c2a769b5670b2b9..9b5bc119a84bffdc67600e5e0ae7a1e416ecb89e 100644 --- a/src/audio/Audio.js +++ b/src/audio/Audio.js @@ -1,5 +1,6 @@ /** * @author mrdoob / http://mrdoob.com/ + * @author Reece Aaron Lecrivain / http://reecenotes.com/ */ THREE.Audio = function ( listener ) { @@ -36,14 +37,9 @@ THREE.Audio.prototype.getOutput = function () { }; -THREE.Audio.prototype.load = function ( file ) { +THREE.Audio.prototype.load = function () { - var buffer = new THREE.AudioBuffer( this.context ); - buffer.load( file ); - - this.setBuffer( buffer ); - - return this; + console.warn( 'THREE.Audio: .load has been deprecated. Please use THREE.AudioLoader.' ); }; @@ -62,13 +58,9 @@ THREE.Audio.prototype.setBuffer = function ( audioBuffer ) { var scope = this; - audioBuffer.onReady( function( buffer ) { - - scope.source.buffer = buffer; - scope.sourceType = 'buffer'; - if ( scope.autoplay ) scope.play(); - - } ); + scope.source.buffer = audioBuffer; + scope.sourceType = 'buffer'; + if ( scope.autoplay ) scope.play(); return this; diff --git a/src/audio/AudioBuffer.js b/src/audio/AudioBuffer.js index c280ec69950ece12b774231026986de42c34513d..e2227bd52a9d0d22baff53ea492b8525955c5790 100644 --- a/src/audio/AudioBuffer.js +++ b/src/audio/AudioBuffer.js @@ -1,56 +1,22 @@ /** * @author mrdoob / http://mrdoob.com/ + * @author Reece Aaron Lecrivain / http://reecenotes.com/ */ THREE.AudioBuffer = function ( context ) { - this.context = context; - this.ready = false; - this.readyCallbacks = []; + console.warn( 'THREE.AudioBuffer has been deprecated. Please use THREE.AudioLoader.' ); }; THREE.AudioBuffer.prototype.load = function ( file ) { - var scope = this; - - var request = new XMLHttpRequest(); - request.open( 'GET', file, true ); - request.responseType = 'arraybuffer'; - request.onload = function ( e ) { - - scope.context.decodeAudioData( this.response, function ( buffer ) { - - scope.buffer = buffer; - scope.ready = true; - - for ( var i = 0; i < scope.readyCallbacks.length; i ++ ) { - - scope.readyCallbacks[ i ]( scope.buffer ); - - } - - scope.readyCallbacks = []; - - } ); - - }; - request.send(); - - return this; + console.warn( 'THREE.AudioBuffer: .load has been deprecated. Please use THREE.AudioLoader.' ); }; THREE.AudioBuffer.prototype.onReady = function ( callback ) { - if ( this.ready ) { - - callback( this.buffer ); - - } else { + console.warn( 'THREE.AudioBuffer: .onReady has been deprecated. Please use THREE.AudioLoader.' ); - this.readyCallbacks.push( callback ); - - } - -}; +}; \ No newline at end of file diff --git a/src/loaders/AudioLoader.js b/src/loaders/AudioLoader.js new file mode 100644 index 0000000000000000000000000000000000000000..ca3ae2776638620e937db7a74f064c8a8de150a3 --- /dev/null +++ b/src/loaders/AudioLoader.js @@ -0,0 +1,35 @@ +/** + * @author Reece Aaron Lecrivain / http://reecenotes.com/ + */ + +THREE.AudioLoader = function ( context, manager ) { + + this.context = ( context !== undefined ) ? context : new ( window.AudioContext || window.webkitAudioContext )(); + + this.manager = ( manager !== undefined ) ? manager : THREE.DefaultLoadingManager; + +}; + +THREE.AudioLoader.prototype = { + + constructor: THREE.AudioLoader, + + load: function( url, onLoad, onProgress, onError ) { + + var scope = this; + + var loader = new THREE.XHRLoader( this.manager ); + loader.setResponseType( 'arraybuffer' ); + loader.load( url, function ( buffer ) { + + scope.context.decodeAudioData( buffer, function ( audioBuffer ) { + + onLoad( audioBuffer ); + + } ); + + }, onProgress, onError ); + + } + +}; \ No newline at end of file