AudioLoader.html 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8" />
  5. <base href="../../../" />
  6. <script src="list.js"></script>
  7. <script src="page.js"></script>
  8. <link type="text/css" rel="stylesheet" href="page.css" />
  9. </head>
  10. <body>
  11. [page:Loader] &rarr;
  12. <h1>[name]</h1>
  13. <p class="desc">
  14. Class for loading an
  15. [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer AudioBuffer].
  16. This uses the [page:FileLoader] internally for loading files.
  17. </p>
  18. <h2>Code Example</h2>
  19. <code>
  20. // instantiate a listener
  21. var audioListener = new THREE.AudioListener();
  22. // add the listener to the camera
  23. camera.add( audioListener );
  24. // instantiate audio object
  25. var oceanAmbientSound = new THREE.Audio( audioListener );
  26. // add the audio object to the scene
  27. scene.add( oceanAmbientSound );
  28. // instantiate a loader
  29. var loader = new THREE.AudioLoader();
  30. // load a resource
  31. loader.load(
  32. // resource URL
  33. 'audio/ambient_ocean.ogg',
  34. // onLoad callback
  35. function ( audioBuffer ) {
  36. // set the audio object buffer to the loaded object
  37. oceanAmbientSound.setBuffer( audioBuffer );
  38. // play the audio
  39. oceanAmbientSound.play();
  40. },
  41. // onProgress callback
  42. function ( xhr ) {
  43. console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  44. },
  45. // onError callback
  46. function ( err ) {
  47. console.log( 'An error happened' );
  48. }
  49. );
  50. </code>
  51. <h2>Constructor</h2>
  52. <h3>[name]( [param:LoadingManager manager] )</h3>
  53. <p>
  54. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  55. Creates a new [name].
  56. </p>
  57. <h2>Properties</h2>
  58. <p>See the base [page:Loader] class for common properties.</p>
  59. <h2>Methods</h2>
  60. <p>See the base [page:Loader] class for common methods.</p>
  61. <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  62. <p>
  63. [page:String url] — the path or URL to the file. This can also be a
  64. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  65. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded text response.<br />
  66. [page:Function onProgress] — Will be called while load progresses. The argument will be the XMLHttpRequest instance, which contains .[page:Integer total] and .[page:Integer loaded] bytes.<br />
  67. [page:Function onError] — Will be called when load errors.<br />
  68. </p>
  69. <p>
  70. Begin loading from url and pass the loaded [page:String AudioBuffer] to onLoad.
  71. </p>
  72. <h2>Source</h2>
  73. <p>
  74. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  75. </p>
  76. </body>
  77. </html>