Audio.html 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203
  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. [page:Object3D] &rarr;
  12. <h1>[name]</h1>
  13. <div class="desc">
  14. Create a non-positional ( global ) audio object.<br /><br />
  15. This uses the [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API Web Audio API].
  16. </div>
  17. <h2>Example</h2>
  18. <div>[example:misc_sound misc / sound ]</div>
  19. <code>
  20. //Create an AudioListener and add it to the camera
  21. var listener = new THREE.AudioListener();
  22. camera.add( listener );
  23. // create a global audio source
  24. var sound = new THREE.Audio( listener );
  25. var audioLoader = new THREE.AudioLoader();
  26. //Load a sound and set it as the Audio object's buffer
  27. audioLoader.load( 'sounds/ambient.ogg', function( buffer ) {
  28. sound.setBuffer( buffer );
  29. sound.setLoop(true);
  30. sound.setVolume(0.5);
  31. sound.play();
  32. });
  33. </code>
  34. <h2>Constructor</h2>
  35. <h3>[name]( [page:AudioListener listener] )</h3>
  36. <div>
  37. listener — (required) [page:AudioListener AudioListener] instance.
  38. </div>
  39. <h2>Properties</h2>
  40. <h3>[property:Boolean autoplay]</h3>
  41. <div>Whether to start playback automatically. Default is *false*.</div>
  42. <h3>[property:AudioContext context]</h3>
  43. <div>The [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext AudioContext] of the [page:AudioListener listener] given in the constructor.</div>
  44. <h3>[property:Array filters]</h3>
  45. <div>Whether the audio is currently playing. Default is empty array.</div>
  46. <h3>[property:GainNode gain]</h3>
  47. <div>A [link:https://developer.mozilla.org/en-US/docs/Web/API/GainNode GainNode] created
  48. using [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createGain AudioContext.createGain]().</div>
  49. <h3>[property:Boolean hasPlaybackControl]</h3>
  50. <div>Whether playback can be controlled using the [page:Audio.play play](),
  51. [page:Audio.pause pause]() etc. methods. Default is *true*.</div>
  52. <h3>[property:Number playbackRate]</h3>
  53. <div>Speed of playback. Default is *1*.</div>
  54. <h3>[property:Boolean isPlaying]</h3>
  55. <div>Whether the audio is currently playing.</div>
  56. <h3>[property:Number startTime]</h3>
  57. <div>Point at which to start playback. Default is *0*.</div>
  58. <h3>[property:String source]</h3>
  59. <div>An [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode AudioBufferSourceNode] created
  60. using [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createBufferSource AudioContext.createBufferSource]().</div>
  61. <h3>[property:String sourceType]</h3>
  62. <div>Type of the audio source. Default is string 'empty'.</div>
  63. <h3>[property:String type]</h3>
  64. <div>String denoting the type, set to 'Audio'.</div>
  65. <h2>Methods</h2>
  66. <h3>[method:null connect]()</h3>
  67. <div>
  68. Connect to the [page:Audio.source]. This is used internally on initialisation and when
  69. setting / removing filters.
  70. </div>
  71. <h3>[method:null disconnect]()</h3>
  72. <div>
  73. Disconnect from the [page:Audio.source]. This is used internally when
  74. setting / removing filters.
  75. </div>
  76. <h3>[method:Array getFilter]()</h3>
  77. <div>
  78. Returns the first element of the [page:Audio.filters filters] array.
  79. </div>
  80. <h3>[method:null getFilters]()</h3>
  81. <div>
  82. Returns the [page:Audio.filters filters] array.
  83. </div>
  84. <h3>[method:Boolean getLoop]()</h3>
  85. <div>
  86. Return the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop]
  87. (whether playback should loop).
  88. </div>
  89. <h3>[method:GainNode getOutput]()</h3>
  90. <div>
  91. Return the [page:Audio.gain gainNode].
  92. </div>
  93. <h3>[method:Number getPlaybackRate]()</h3>
  94. <div>
  95. Return the value of [page:Audio.playbackRate playbackRate].
  96. </div>
  97. <h3>[method:Number getVolume]( value )</h3>
  98. <div>
  99. Return the current volume.
  100. </div>
  101. <h3>[method:null play]()</h3>
  102. <div>
  103. If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, starts playback.
  104. </div>
  105. <h3>[method:null pause]()</h3>
  106. <div>
  107. If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, pauses playback.
  108. </div>
  109. <h3>[method:null onEnded]()</h3>
  110. <div>
  111. Called automatically when playback finished. Sets If [page:Audio.isPlaying isPlaying] to false.
  112. </div>
  113. <h3>[method:Audio setBuffer]( audioBuffer )</h3>
  114. <div>
  115. Setup the [page:Audio.source source] to the audioBuffer, and sets [page:Audio.sourceType sourceType] to 'buffer'.<br />
  116. If [page:Audio.autoplay autoplay], also starts playback.
  117. </div>
  118. <h3>[method:null setFilter]( filter )</h3>
  119. <div>
  120. Add the filter to the [page:Audio.filters filters] array.
  121. </div>
  122. <h3>[method:Audio setFilters]( [page:Array value] )</h3>
  123. <div>
  124. value - arrays of filters.<br />
  125. Set the [page:Audio.filters filters] array to *value*.
  126. </div>
  127. <h3>[method:null setLoop]( [page:Boolean value] )</h3>
  128. <div>
  129. Set [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop] to *value*
  130. (whether playback should loop).
  131. </div>
  132. <h3>[method:null setNodeSource]( audioNode )</h3>
  133. <div>
  134. Setup the [page:Audio.source source] to the audioBuffer, and sets [page:Audio.sourceType sourceType] to 'audioNode'.<br />
  135. Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.
  136. </div>
  137. <h3>[method:null setPlaybackRate]( [page:Number value] )</h3>
  138. <div>
  139. If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, set the [page:Audio.playbackRate playbackRate] to *value*.
  140. </div>
  141. <h3>[method:null setVolume]( [page:Number value] )</h3>
  142. <div>
  143. Set the volume.
  144. </div>
  145. <h3>[method:null stop]()</h3>
  146. <div>
  147. If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, stops playback,
  148. resets [page:Audio.startTime startTime] to *0* and sets [page:Audio.isPlaying isPlaying] to false.
  149. </div>
  150. <h2>Source</h2>
  151. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  152. </body>
  153. </html>