Audio.html 7.0 KB

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