AudioLoader.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  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
  16. files.
  17. </p>
  18. <h2>Code Example</h2>
  19. <code>
  20. // instantiate a listener
  21. const audioListener = new THREE.AudioListener();
  22. // add the listener to the camera
  23. camera.add( audioListener );
  24. // instantiate audio object
  25. const oceanAmbientSound = new THREE.Audio( audioListener );
  26. // add the audio object to the scene
  27. scene.add( oceanAmbientSound );
  28. // instantiate a loader
  29. const 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]
  55. for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
  56. Creates a new [name].
  57. </p>
  58. <h2>Properties</h2>
  59. <p>See the base [page:Loader] class for common properties.</p>
  60. <h2>Methods</h2>
  61. <p>See the base [page:Loader] class for common methods.</p>
  62. <h3>
  63. [method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )
  64. </h3>
  65. <p>
  66. [page:String url] — the path or URL to the file. This can also be a
  67. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  68. [page:Function onLoad] — Will be called when load completes. The argument
  69. will be the loaded text response.<br />
  70. [page:Function onProgress] (optional) — Will be called while load
  71. progresses. The argument will be the ProgressEvent instance, which
  72. contains .[page:Boolean lengthComputable], .[page:Integer total] and
  73. .[page:Integer loaded]. If the server does not set the Content-Length
  74. header; .[page:Integer total] will be 0.<br />
  75. [page:Function onError] (optional) — Will be called when load errors.<br />
  76. </p>
  77. <p>
  78. Begin loading from url and pass the loaded [page:String AudioBuffer] to
  79. onLoad.
  80. </p>
  81. <h2>Source</h2>
  82. <p>
  83. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  84. </p>
  85. </body>
  86. </html>