AudioLoader.html 2.5 KB

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