AudioLoader.js 980 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import { AudioContext } from '../audio/AudioContext.js';
  2. import { FileLoader } from './FileLoader.js';
  3. import { Loader } from './Loader.js';
  4. /**
  5. * @author Reece Aaron Lecrivain / http://reecenotes.com/
  6. */
  7. function AudioLoader( manager ) {
  8. Loader.call( this, manager );
  9. }
  10. AudioLoader.prototype = Object.assign( Object.create( Loader.prototype ), {
  11. constructor: AudioLoader,
  12. load: function ( url, onLoad, onProgress, onError ) {
  13. var loader = new FileLoader( this.manager );
  14. loader.setResponseType( 'arraybuffer' );
  15. loader.setPath( this.path );
  16. loader.load( url, function ( buffer ) {
  17. // Create a copy of the buffer. The `decodeAudioData` method
  18. // detaches the buffer when complete, preventing reuse.
  19. var bufferCopy = buffer.slice( 0 );
  20. var context = AudioContext.getContext();
  21. context.decodeAudioData( bufferCopy, function ( audioBuffer ) {
  22. onLoad( audioBuffer );
  23. } );
  24. }, onProgress, onError );
  25. }
  26. } );
  27. export { AudioLoader };