提交 ccbccc52 编写于 作者: R Reece Lecrivain

Add THREE.AudioLoader

上级 99432158
/**
* @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;
......
/**
* @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
/**
* @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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册