AudioLoader.html 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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. <div class="desc">Class for loading an [page:String AudioBuffer].</div>
  13. <h2>Constructor</h2>
  14. <h3>[name]( [page:String context], [page:LoadingManager manager] )</h3>
  15. <div>
  16. [page:String context] — The [page:String AudioContext] for the loader to use. Default is [page:String window.AudioContext].<br />
  17. [page:LoadingManager manager] — The [page:LoadingManager loadingManager] for the loader to use. Default is [page:LoadingManager THREE.DefaultLoadingManager].
  18. </div>
  19. <div>
  20. Creates a new [name].
  21. </div>
  22. <h2>Methods</h2>
  23. <h3>[method:null load]( [page:String url], [page:Function onLoad], [page:Function onProgress], [page:Function onError] )</h3>
  24. <div>
  25. [page:String url] — required<br />
  26. [page:Function onLoad] — Will be called when load completes. The argument will be the loaded text response.<br />
  27. [page:Function onProgress] — Will be called while load progresses. The argument will be the XmlHttpRequest instance, that contain .[page:Integer total] and .[page:Integer loaded] bytes.<br />
  28. [page:Function onError] — Will be called when load errors.<br />
  29. </div>
  30. <div>
  31. Begin loading from url and pass the loaded [page:String AudioBuffer] to onLoad.
  32. </div>
  33. <h2>Example</h2>
  34. <code>
  35. // instantiate a listener
  36. var audioListener = new THREE.AudioListener();
  37. // add the listener to the camera
  38. camera.add( audioListener );
  39. // instantiate audio object
  40. var oceanAmbientSound = new THREE.Audio( audioListener );
  41. // add the audio object to the scene
  42. scene.add( oceanAmbientSound );
  43. // instantiate a loader
  44. var loader = new THREE.AudioLoader();
  45. // load a resource
  46. loader.load(
  47. // resource URL
  48. 'audio/ambient_ocean.ogg',
  49. // Function when resource is loaded
  50. function ( audioBuffer ) {
  51. // set the audio object buffer to the loaded object
  52. oceanAmbientSound.setBuffer( audioBuffer );
  53. // play the audio
  54. oceanAmbientSound.play();
  55. },
  56. // Function called when download progresses
  57. function ( xhr ) {
  58. console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
  59. },
  60. // Function called when download errors
  61. function ( xhr ) {
  62. console.log( 'An error happened' );
  63. }
  64. );
  65. </code>
  66. <h2>Source</h2>
  67. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  68. </body>
  69. </html>