AudioLoader.html 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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. <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>Example</h2>
  18. <code>
  19. // instantiate a listener
  20. var audioListener = new THREE.AudioListener();
  21. // add the listener to the camera
  22. camera.add( audioListener );
  23. // instantiate audio object
  24. var oceanAmbientSound = new THREE.Audio( audioListener );
  25. // add the audio object to the scene
  26. scene.add( oceanAmbientSound );
  27. // instantiate a loader
  28. var 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:String context], [param:LoadingManager manager] )</h3>
  52. <p>
  53. [page:String context] — The [page:String AudioContext] for the loader to use. Default is [page:String window.AudioContext].<br />
  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. <h3>[property:LoadingManager manager]</h3>
  59. <p>
  60. The [page:LoadingManager loadingManager] the loader is using. Default is [page:DefaultLoadingManager].
  61. </p>
  62. <h2>Methods</h2>
  63. <h3>[method:null load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
  64. <p>
  65. [page:String url] — the path or URL to the file. This can also be a
  66. [link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
  67. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded text response.<br />
  68. [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 />
  69. [page:Function onError] — Will be called when load errors.<br />
  70. </p>
  71. <p>
  72. Begin loading from url and pass the loaded [page:String AudioBuffer] to onLoad.
  73. </p>
  74. <h2>Source</h2>
  75. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  76. </body>
  77. </html>