Audio.html 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  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>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*.</div>
  58. <h3>[property:Number offset]</h3>
  59. <div>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*.</div>
  60. <h3>[property:String source]</h3>
  61. <div>An [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode AudioBufferSourceNode] created
  62. using [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createBufferSource AudioContext.createBufferSource]().</div>
  63. <h3>[property:String sourceType]</h3>
  64. <div>Type of the audio source. Default is string 'empty'.</div>
  65. <h3>[property:String type]</h3>
  66. <div>String denoting the type, set to 'Audio'.</div>
  67. <h2>Methods</h2>
  68. <h3>[method:null connect]()</h3>
  69. <div>
  70. Connect to the [page:Audio.source]. This is used internally on initialisation and when
  71. setting / removing filters.
  72. </div>
  73. <h3>[method:null disconnect]()</h3>
  74. <div>
  75. Disconnect from the [page:Audio.source]. This is used internally when
  76. setting / removing filters.
  77. </div>
  78. <h3>[method:Array getFilter]()</h3>
  79. <div>
  80. Returns the first element of the [page:Audio.filters filters] array.
  81. </div>
  82. <h3>[method:null getFilters]()</h3>
  83. <div>
  84. Returns the [page:Audio.filters filters] array.
  85. </div>
  86. <h3>[method:Boolean getLoop]()</h3>
  87. <div>
  88. Return the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop]
  89. (whether playback should loop).
  90. </div>
  91. <h3>[method:GainNode getOutput]()</h3>
  92. <div>
  93. Return the [page:Audio.gain gainNode].
  94. </div>
  95. <h3>[method:Number getPlaybackRate]()</h3>
  96. <div>
  97. Return the value of [page:Audio.playbackRate playbackRate].
  98. </div>
  99. <h3>[method:Number getVolume]( value )</h3>
  100. <div>
  101. Return the current volume.
  102. </div>
  103. <h3>[method:null play]()</h3>
  104. <div>
  105. If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, starts playback.
  106. </div>
  107. <h3>[method:null pause]()</h3>
  108. <div>
  109. If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, pauses playback.
  110. </div>
  111. <h3>[method:null onEnded]()</h3>
  112. <div>
  113. Called automatically when playback finished. Sets If [page:Audio.isPlaying isPlaying] to false.
  114. </div>
  115. <h3>[method:Audio setBuffer]( audioBuffer )</h3>
  116. <div>
  117. Setup the [page:Audio.source source] to the audioBuffer, and sets [page:Audio.sourceType sourceType] to 'buffer'.<br />
  118. If [page:Audio.autoplay autoplay], also starts playback.
  119. </div>
  120. <h3>[method:null setFilter]( filter )</h3>
  121. <div>
  122. Add the filter to the [page:Audio.filters filters] array.
  123. </div>
  124. <h3>[method:Audio setFilters]( [page:Array value] )</h3>
  125. <div>
  126. value - arrays of filters.<br />
  127. Set the [page:Audio.filters filters] array to *value*.
  128. </div>
  129. <h3>[method:null setLoop]( [page:Boolean value] )</h3>
  130. <div>
  131. Set [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop] to *value*
  132. (whether playback should loop).
  133. </div>
  134. <h3>[method:null setNodeSource]( audioNode )</h3>
  135. <div>
  136. Setup the [page:Audio.source source] to the audioBuffer, and sets [page:Audio.sourceType sourceType] to 'audioNode'.<br />
  137. Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.
  138. </div>
  139. <h3>[method:null setPlaybackRate]( [page:Number value] )</h3>
  140. <div>
  141. If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, set the [page:Audio.playbackRate playbackRate] to *value*.
  142. </div>
  143. <h3>[method:null setVolume]( [page:Number value] )</h3>
  144. <div>
  145. Set the volume.
  146. </div>
  147. <h3>[method:null stop]()</h3>
  148. <div>
  149. If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, stops playback,
  150. resets [page:Audio.startTime startTime] to *0* and sets [page:Audio.isPlaying isPlaying] to false.
  151. </div>
  152. <h2>Source</h2>
  153. [link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
  154. </body>
  155. </html>