AudioLoader.html 2.7 KB

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