Audio.html 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>Audio - Three.js Docs</title>
  6. <meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
  7. <script src="../scripts/highlight.min.js"></script>
  8. <link type="text/css" rel="stylesheet" href="../styles/highlight-three.css">
  9. <link type="text/css" rel="stylesheet" href="../styles/page.css">
  10. </head>
  11. <body>
  12. <p class="inheritance" translate="no"><a href="EventDispatcher.html">EventDispatcher</a> → <a href="Object3D.html">Object3D</a> → </p>
  13. <h1 translate="no">Audio</h1>
  14. <section>
  15. <header>
  16. <div class="class-description"><p>Represents a non-positional ( global ) audio object.</p>
  17. <p>This and related audio modules make use of the <a href="https://www.w3.org/TR/webaudio-1.1/" target="_blank" rel="noopener">Web Audio API</a>.</p></div>
  18. <h2>Code Example</h2>
  19. <div translate="no"><pre><code class="language-js">// create an AudioListener and add it to the camera
  20. const listener = new THREE.AudioListener();
  21. camera.add( listener );
  22. // create a global audio source
  23. const sound = new THREE.Audio( listener );
  24. // load a sound and set it as the Audio object's buffer
  25. const audioLoader = new THREE.AudioLoader();
  26. audioLoader.load( 'sounds/ambient.ogg', function( buffer ) {
  27. sound.setBuffer( buffer );
  28. sound.setLoop( true );
  29. sound.setVolume( 0.5 );
  30. sound.play();
  31. });
  32. </code></pre></div>
  33. </header>
  34. <article>
  35. <div class="container-overview">
  36. <h2>Constructor</h2>
  37. <h3 class="name name-method" id="Audio" translate="no">new <a href="#Audio">Audio</a><span class="signature">( listener : <span class="param-type"><a href="AudioListener.html">AudioListener</a></span> )</span> </h3>
  38. <div class="method">
  39. <div class="description">
  40. <p>Constructs a new audio.</p>
  41. </div>
  42. <table class="params">
  43. <tbody>
  44. <tr>
  45. <td class="name">
  46. <strong>listener</strong>
  47. </td>
  48. <td class="description last">
  49. <p>The global audio listener.</p>
  50. </td>
  51. </tr>
  52. </tbody>
  53. </table>
  54. </div>
  55. </div>
  56. <h2 class="subsection-title">Properties</h2>
  57. <div class="member">
  58. <h3 class="name" id="autoplay" translate="no">.<a href="#autoplay">autoplay</a><span class="type-signature"> : boolean</span> </h3>
  59. <div class="description">
  60. <p>Whether to start playback automatically or not.</p>
  61. <p>Default is <code>false</code>.</p>
  62. </div>
  63. </div>
  64. <div class="member">
  65. <h3 class="name" id="buffer" translate="no">.<a href="#buffer">buffer</a><span class="type-signature"> : AudioBuffer</span> <span class="type-signature">(readonly) </span></h3>
  66. <div class="description">
  67. <p>A reference to an audio buffer.</p>
  68. <p>Defined via <a href="Audio.html#setBuffer">Audio#setBuffer</a>.</p>
  69. <p>Default is <code>null</code>.</p>
  70. </div>
  71. </div>
  72. <div class="member">
  73. <h3 class="name" id="context" translate="no">.<a href="#context">context</a><span class="type-signature"> : <a href="AudioContext.html">AudioContext</a></span> <span class="type-signature">(readonly) </span></h3>
  74. <div class="description">
  75. <p>The audio context.</p>
  76. </div>
  77. </div>
  78. <div class="member">
  79. <h3 class="name" id="detune" translate="no">.<a href="#detune">detune</a><span class="type-signature"> : number</span> <span class="type-signature">(readonly) </span></h3>
  80. <div class="description">
  81. <p>Modify pitch, measured in cents. +/- 100 is a semitone.
  82. +/- 1200 is an octave.</p>
  83. <p>Defined via <a href="Audio.html#setDetune">Audio#setDetune</a>.</p>
  84. <p>Default is <code>0</code>.</p>
  85. </div>
  86. </div>
  87. <div class="member">
  88. <h3 class="name" id="duration" translate="no">.<a href="#duration">duration</a><span class="type-signature"> : undefined | number</span> </h3>
  89. <div class="description">
  90. <p>Overrides the default duration of the audio.</p>
  91. <p>Default is <code>undefined</code>.</p>
  92. </div>
  93. </div>
  94. <div class="member">
  95. <h3 class="name" id="filters" translate="no">.<a href="#filters">filters</a><span class="type-signature"> : Array.&lt;AudioNode></span> <span class="type-signature">(readonly) </span></h3>
  96. <div class="description">
  97. <p>Can be used to apply a variety of low-order filters to create
  98. more complex sound effects e.g. via <code>BiquadFilterNode</code>.</p>
  99. <p>The property is automatically set by <a href="Audio.html#setFilters">Audio#setFilters</a>.</p>
  100. </div>
  101. </div>
  102. <div class="member">
  103. <h3 class="name" id="gain" translate="no">.<a href="#gain">gain</a><span class="type-signature"> : GainNode</span> <span class="type-signature">(readonly) </span></h3>
  104. <div class="description">
  105. <p>The gain node used for volume control.</p>
  106. </div>
  107. </div>
  108. <div class="member">
  109. <h3 class="name" id="hasPlaybackControl" translate="no">.<a href="#hasPlaybackControl">hasPlaybackControl</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  110. <div class="description">
  111. <p>Indicates whether the audio playback can be controlled
  112. with method like <a href="Audio.html#play">Audio#play</a> or <a href="Audio.html#pause">Audio#pause</a>.</p>
  113. <p>This flag will be automatically set when audio sources are
  114. defined.</p>
  115. <p>Default is <code>true</code>.</p>
  116. </div>
  117. </div>
  118. <div class="member">
  119. <h3 class="name" id="isPlaying" translate="no">.<a href="#isPlaying">isPlaying</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  120. <div class="description">
  121. <p>Indicates whether the audio is playing or not.</p>
  122. <p>This flag will be automatically set when using <a href="Audio.html#play">Audio#play</a>,
  123. <a href="Audio.html#pause">Audio#pause</a>, <a href="Audio.html#stop">Audio#stop</a>.</p>
  124. <p>Default is <code>false</code>.</p>
  125. </div>
  126. </div>
  127. <div class="member">
  128. <h3 class="name" id="listener" translate="no">.<a href="#listener">listener</a><span class="type-signature"> : <a href="AudioListener.html">AudioListener</a></span> <span class="type-signature">(readonly) </span></h3>
  129. <div class="description">
  130. <p>The global audio listener.</p>
  131. </div>
  132. </div>
  133. <div class="member">
  134. <h3 class="name" id="loop" translate="no">.<a href="#loop">loop</a><span class="type-signature"> : boolean</span> <span class="type-signature">(readonly) </span></h3>
  135. <div class="description">
  136. <p>Whether the audio should loop or not.</p>
  137. <p>Defined via <a href="Audio.html#setLoop">Audio#setLoop</a>.</p>
  138. <p>Default is <code>false</code>.</p>
  139. </div>
  140. </div>
  141. <div class="member">
  142. <h3 class="name" id="loopEnd" translate="no">.<a href="#loopEnd">loopEnd</a><span class="type-signature"> : number</span> </h3>
  143. <div class="description">
  144. <p>Defines where in the audio buffer the replay should
  145. stop, in seconds.</p>
  146. <p>Default is <code>0</code>.</p>
  147. </div>
  148. </div>
  149. <div class="member">
  150. <h3 class="name" id="loopStart" translate="no">.<a href="#loopStart">loopStart</a><span class="type-signature"> : number</span> </h3>
  151. <div class="description">
  152. <p>Defines where in the audio buffer the replay should
  153. start, in seconds.</p>
  154. <p>Default is <code>0</code>.</p>
  155. </div>
  156. </div>
  157. <div class="member">
  158. <h3 class="name" id="offset" translate="no">.<a href="#offset">offset</a><span class="type-signature"> : number</span> </h3>
  159. <div class="description">
  160. <p>An offset to the time within the audio buffer the playback
  161. should begin, in seconds.</p>
  162. <p>Default is <code>0</code>.</p>
  163. </div>
  164. </div>
  165. <div class="member">
  166. <h3 class="name" id="playbackRate" translate="no">.<a href="#playbackRate">playbackRate</a><span class="type-signature"> : number</span> <span class="type-signature">(readonly) </span></h3>
  167. <div class="description">
  168. <p>The playback speed.</p>
  169. <p>Defined via <a href="Audio.html#setPlaybackRate">Audio#setPlaybackRate</a>.</p>
  170. <p>Default is <code>1</code>.</p>
  171. </div>
  172. </div>
  173. <div class="member">
  174. <h3 class="name" id="source" translate="no">.<a href="#source">source</a><span class="type-signature"> : AudioNode</span> <span class="type-signature">(readonly) </span></h3>
  175. <div class="description">
  176. <p>Holds a reference to the current audio source.</p>
  177. <p>The property is automatically by one of the <code>set*()</code> methods.</p>
  178. <p>Default is <code>null</code>.</p>
  179. </div>
  180. </div>
  181. <div class="member">
  182. <h3 class="name" id="sourceType" translate="no">.<a href="#sourceType">sourceType</a><span class="type-signature"> : 'empty' | 'audioNode' | 'mediaNode' | 'mediaStreamNode' | 'buffer'</span> <span class="type-signature">(readonly) </span></h3>
  183. <div class="description">
  184. <p>Defines the source type.</p>
  185. <p>The property is automatically set by one of the <code>set*()</code> methods.</p>
  186. <p>Default is <code>'empty'</code>.</p>
  187. </div>
  188. </div>
  189. <h2 class="subsection-title">Methods</h2>
  190. <h3 class="name name-method" id="connect" translate="no">.<a href="#connect">connect</a><span class="signature">()</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  191. <div class="method">
  192. <div class="description">
  193. <p>Connects to the audio source. This is used internally on
  194. initialisation and when setting / removing filters.</p>
  195. </div>
  196. <dl class="details">
  197. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  198. </dl>
  199. </div>
  200. <h3 class="name name-method" id="disconnect" translate="no">.<a href="#disconnect">disconnect</a><span class="signature">()</span><span class="type-signature"> : <a href="Audio.html">Audio</a> | undefined</span> </h3>
  201. <div class="method">
  202. <div class="description">
  203. <p>Disconnects to the audio source. This is used internally on
  204. initialisation and when setting / removing filters.</p>
  205. </div>
  206. <dl class="details">
  207. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  208. </dl>
  209. </div>
  210. <h3 class="name name-method" id="getDetune" translate="no">.<a href="#getDetune">getDetune</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  211. <div class="method">
  212. <div class="description">
  213. <p>Returns the detuning of oscillation in cents.</p>
  214. </div>
  215. <dl class="details">
  216. <dt class="tag-returns"><strong>Returns:</strong> The detuning of oscillation in cents.</dt>
  217. </dl>
  218. </div>
  219. <h3 class="name name-method" id="getFilter" translate="no">.<a href="#getFilter">getFilter</a><span class="signature">()</span><span class="type-signature"> : AudioNode | undefined</span> </h3>
  220. <div class="method">
  221. <div class="description">
  222. <p>Returns the first filter in the list of filters.</p>
  223. </div>
  224. <dl class="details">
  225. <dt class="tag-returns"><strong>Returns:</strong> The first filter in the list of filters.</dt>
  226. </dl>
  227. </div>
  228. <h3 class="name name-method" id="getFilters" translate="no">.<a href="#getFilters">getFilters</a><span class="signature">()</span><span class="type-signature"> : Array.&lt;AudioNode></span> </h3>
  229. <div class="method">
  230. <div class="description">
  231. <p>Returns the current set filters.</p>
  232. </div>
  233. <dl class="details">
  234. <dt class="tag-returns"><strong>Returns:</strong> The list of filters.</dt>
  235. </dl>
  236. </div>
  237. <h3 class="name name-method" id="getLoop" translate="no">.<a href="#getLoop">getLoop</a><span class="signature">()</span><span class="type-signature"> : boolean</span> </h3>
  238. <div class="method">
  239. <div class="description">
  240. <p>Returns the loop flag.</p>
  241. <p>Can only be used with compatible audio sources that allow playback control.</p>
  242. </div>
  243. <dl class="details">
  244. <dt class="tag-returns"><strong>Returns:</strong> Whether the audio should loop or not.</dt>
  245. </dl>
  246. </div>
  247. <h3 class="name name-method" id="getOutput" translate="no">.<a href="#getOutput">getOutput</a><span class="signature">()</span><span class="type-signature"> : GainNode</span> </h3>
  248. <div class="method">
  249. <div class="description">
  250. <p>Returns the output audio node.</p>
  251. </div>
  252. <dl class="details">
  253. <dt class="tag-returns"><strong>Returns:</strong> The output node.</dt>
  254. </dl>
  255. </div>
  256. <h3 class="name name-method" id="getPlaybackRate" translate="no">.<a href="#getPlaybackRate">getPlaybackRate</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  257. <div class="method">
  258. <div class="description">
  259. <p>Returns the current playback rate.</p>
  260. </div>
  261. <dl class="details">
  262. <dt class="tag-returns"><strong>Returns:</strong> The playback rate.</dt>
  263. </dl>
  264. </div>
  265. <h3 class="name name-method" id="getVolume" translate="no">.<a href="#getVolume">getVolume</a><span class="signature">()</span><span class="type-signature"> : number</span> </h3>
  266. <div class="method">
  267. <div class="description">
  268. <p>Returns the volume.</p>
  269. </div>
  270. <dl class="details">
  271. <dt class="tag-returns"><strong>Returns:</strong> The volume.</dt>
  272. </dl>
  273. </div>
  274. <h3 class="name name-method" id="onEnded" translate="no">.<a href="#onEnded">onEnded</a><span class="signature">()</span> </h3>
  275. <div class="method">
  276. <div class="description">
  277. <p>Automatically called when playback finished.</p>
  278. </div>
  279. </div>
  280. <h3 class="name name-method" id="pause" translate="no">.<a href="#pause">pause</a><span class="signature">()</span><span class="type-signature"> : <a href="Audio.html">Audio</a> | undefined</span> </h3>
  281. <div class="method">
  282. <div class="description">
  283. <p>Pauses the playback of the audio.</p>
  284. <p>Can only be used with compatible audio sources that allow playback control.</p>
  285. </div>
  286. <dl class="details">
  287. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  288. </dl>
  289. </div>
  290. <h3 class="name name-method" id="play" translate="no">.<a href="#play">play</a><span class="signature">( delay : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a> | undefined</span> </h3>
  291. <div class="method">
  292. <div class="description">
  293. <p>Starts the playback of the audio.</p>
  294. <p>Can only be used with compatible audio sources that allow playback control.</p>
  295. </div>
  296. <table class="params">
  297. <tbody>
  298. <tr>
  299. <td class="name">
  300. <strong>delay</strong>
  301. </td>
  302. <td class="description last">
  303. <p>The delay, in seconds, at which the audio should start playing.</p>
  304. <p>Default is <code>0</code>.</p>
  305. </td>
  306. </tr>
  307. </tbody>
  308. </table>
  309. <dl class="details">
  310. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  311. </dl>
  312. </div>
  313. <h3 class="name name-method" id="setBuffer" translate="no">.<a href="#setBuffer">setBuffer</a><span class="signature">( audioBuffer : <span class="param-type">AudioBuffer</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  314. <div class="method">
  315. <div class="description">
  316. <p>Sets the given audio buffer as the source of this instance.</p>
  317. <p><a href="Audio.html#sourceType">Audio#sourceType</a> is set to <code>buffer</code> and <a href="Audio.html#hasPlaybackControl">Audio#hasPlaybackControl</a> to <code>true</code>.</p>
  318. </div>
  319. <table class="params">
  320. <tbody>
  321. <tr>
  322. <td class="name">
  323. <strong>audioBuffer</strong>
  324. </td>
  325. <td class="description last">
  326. <p>The audio buffer.</p>
  327. </td>
  328. </tr>
  329. </tbody>
  330. </table>
  331. <dl class="details">
  332. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  333. </dl>
  334. </div>
  335. <h3 class="name name-method" id="setDetune" translate="no">.<a href="#setDetune">setDetune</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  336. <div class="method">
  337. <div class="description">
  338. <p>Defines the detuning of oscillation in cents.</p>
  339. </div>
  340. <table class="params">
  341. <tbody>
  342. <tr>
  343. <td class="name">
  344. <strong>value</strong>
  345. </td>
  346. <td class="description last">
  347. <p>The detuning of oscillation in cents.</p>
  348. </td>
  349. </tr>
  350. </tbody>
  351. </table>
  352. <dl class="details">
  353. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  354. </dl>
  355. </div>
  356. <h3 class="name name-method" id="setFilter" translate="no">.<a href="#setFilter">setFilter</a><span class="signature">( filter : <span class="param-type">AudioNode</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  357. <div class="method">
  358. <div class="description">
  359. <p>Applies a single filter node to the audio.</p>
  360. </div>
  361. <table class="params">
  362. <tbody>
  363. <tr>
  364. <td class="name">
  365. <strong>filter</strong>
  366. </td>
  367. <td class="description last">
  368. <p>The filter to set.</p>
  369. </td>
  370. </tr>
  371. </tbody>
  372. </table>
  373. <dl class="details">
  374. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  375. </dl>
  376. </div>
  377. <h3 class="name name-method" id="setFilters" translate="no">.<a href="#setFilters">setFilters</a><span class="signature">( value : <span class="param-type">Array.&lt;AudioNode></span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  378. <div class="method">
  379. <div class="description">
  380. <p>Sets an array of filters and connects them with the audio source.</p>
  381. </div>
  382. <table class="params">
  383. <tbody>
  384. <tr>
  385. <td class="name">
  386. <strong>value</strong>
  387. </td>
  388. <td class="description last">
  389. <p>A list of filters.</p>
  390. </td>
  391. </tr>
  392. </tbody>
  393. </table>
  394. <dl class="details">
  395. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  396. </dl>
  397. </div>
  398. <h3 class="name name-method" id="setLoop" translate="no">.<a href="#setLoop">setLoop</a><span class="signature">( value : <span class="param-type">boolean</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a> | undefined</span> </h3>
  399. <div class="method">
  400. <div class="description">
  401. <p>Sets the loop flag.</p>
  402. <p>Can only be used with compatible audio sources that allow playback control.</p>
  403. </div>
  404. <table class="params">
  405. <tbody>
  406. <tr>
  407. <td class="name">
  408. <strong>value</strong>
  409. </td>
  410. <td class="description last">
  411. <p>Whether the audio should loop or not.</p>
  412. </td>
  413. </tr>
  414. </tbody>
  415. </table>
  416. <dl class="details">
  417. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  418. </dl>
  419. </div>
  420. <h3 class="name name-method" id="setLoopEnd" translate="no">.<a href="#setLoopEnd">setLoopEnd</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  421. <div class="method">
  422. <div class="description">
  423. <p>Sets the loop end value which defines where in the audio buffer the replay should
  424. stop, in seconds.</p>
  425. </div>
  426. <table class="params">
  427. <tbody>
  428. <tr>
  429. <td class="name">
  430. <strong>value</strong>
  431. </td>
  432. <td class="description last">
  433. <p>The loop end value.</p>
  434. </td>
  435. </tr>
  436. </tbody>
  437. </table>
  438. <dl class="details">
  439. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  440. </dl>
  441. </div>
  442. <h3 class="name name-method" id="setLoopStart" translate="no">.<a href="#setLoopStart">setLoopStart</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  443. <div class="method">
  444. <div class="description">
  445. <p>Sets the loop start value which defines where in the audio buffer the replay should
  446. start, in seconds.</p>
  447. </div>
  448. <table class="params">
  449. <tbody>
  450. <tr>
  451. <td class="name">
  452. <strong>value</strong>
  453. </td>
  454. <td class="description last">
  455. <p>The loop start value.</p>
  456. </td>
  457. </tr>
  458. </tbody>
  459. </table>
  460. <dl class="details">
  461. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  462. </dl>
  463. </div>
  464. <h3 class="name name-method" id="setMediaElementSource" translate="no">.<a href="#setMediaElementSource">setMediaElementSource</a><span class="signature">( mediaElement : <span class="param-type">HTMLMediaElement</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  465. <div class="method">
  466. <div class="description">
  467. <p>Sets the given media element as the source of this instance.</p>
  468. <p><a href="Audio.html#sourceType">Audio#sourceType</a> is set to <code>mediaNode</code> and <a href="Audio.html#hasPlaybackControl">Audio#hasPlaybackControl</a> to <code>false</code>.</p>
  469. </div>
  470. <table class="params">
  471. <tbody>
  472. <tr>
  473. <td class="name">
  474. <strong>mediaElement</strong>
  475. </td>
  476. <td class="description last">
  477. <p>The media element.</p>
  478. </td>
  479. </tr>
  480. </tbody>
  481. </table>
  482. <dl class="details">
  483. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  484. </dl>
  485. </div>
  486. <h3 class="name name-method" id="setMediaStreamSource" translate="no">.<a href="#setMediaStreamSource">setMediaStreamSource</a><span class="signature">( mediaStream : <span class="param-type">MediaStream</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  487. <div class="method">
  488. <div class="description">
  489. <p>Sets the given media stream as the source of this instance.</p>
  490. <p><a href="Audio.html#sourceType">Audio#sourceType</a> is set to <code>mediaStreamNode</code> and <a href="Audio.html#hasPlaybackControl">Audio#hasPlaybackControl</a> to <code>false</code>.</p>
  491. </div>
  492. <table class="params">
  493. <tbody>
  494. <tr>
  495. <td class="name">
  496. <strong>mediaStream</strong>
  497. </td>
  498. <td class="description last">
  499. <p>The media stream.</p>
  500. </td>
  501. </tr>
  502. </tbody>
  503. </table>
  504. <dl class="details">
  505. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  506. </dl>
  507. </div>
  508. <h3 class="name name-method" id="setNodeSource" translate="no">.<a href="#setNodeSource">setNodeSource</a><span class="signature">( audioNode : <span class="param-type">AudioNode</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  509. <div class="method">
  510. <div class="description">
  511. <p>Sets the given audio node as the source of this instance.</p>
  512. <p><a href="Audio.html#sourceType">Audio#sourceType</a> is set to <code>audioNode</code> and <a href="Audio.html#hasPlaybackControl">Audio#hasPlaybackControl</a> to <code>false</code>.</p>
  513. </div>
  514. <table class="params">
  515. <tbody>
  516. <tr>
  517. <td class="name">
  518. <strong>audioNode</strong>
  519. </td>
  520. <td class="description last">
  521. <p>The audio node like an instance of <code>OscillatorNode</code>.</p>
  522. </td>
  523. </tr>
  524. </tbody>
  525. </table>
  526. <dl class="details">
  527. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  528. </dl>
  529. </div>
  530. <h3 class="name name-method" id="setPlaybackRate" translate="no">.<a href="#setPlaybackRate">setPlaybackRate</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a> | undefined</span> </h3>
  531. <div class="method">
  532. <div class="description">
  533. <p>Sets the playback rate.</p>
  534. <p>Can only be used with compatible audio sources that allow playback control.</p>
  535. </div>
  536. <table class="params">
  537. <tbody>
  538. <tr>
  539. <td class="name">
  540. <strong>value</strong>
  541. </td>
  542. <td class="description last">
  543. <p>The playback rate to set.</p>
  544. </td>
  545. </tr>
  546. </tbody>
  547. </table>
  548. <dl class="details">
  549. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  550. </dl>
  551. </div>
  552. <h3 class="name name-method" id="setVolume" translate="no">.<a href="#setVolume">setVolume</a><span class="signature">( value : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a></span> </h3>
  553. <div class="method">
  554. <div class="description">
  555. <p>Sets the volume.</p>
  556. </div>
  557. <table class="params">
  558. <tbody>
  559. <tr>
  560. <td class="name">
  561. <strong>value</strong>
  562. </td>
  563. <td class="description last">
  564. <p>The volume to set.</p>
  565. </td>
  566. </tr>
  567. </tbody>
  568. </table>
  569. <dl class="details">
  570. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  571. </dl>
  572. </div>
  573. <h3 class="name name-method" id="stop" translate="no">.<a href="#stop">stop</a><span class="signature">( delay : <span class="param-type">number</span> )</span><span class="type-signature"> : <a href="Audio.html">Audio</a> | undefined</span> </h3>
  574. <div class="method">
  575. <div class="description">
  576. <p>Stops the playback of the audio.</p>
  577. <p>Can only be used with compatible audio sources that allow playback control.</p>
  578. </div>
  579. <table class="params">
  580. <tbody>
  581. <tr>
  582. <td class="name">
  583. <strong>delay</strong>
  584. </td>
  585. <td class="description last">
  586. <p>The delay, in seconds, at which the audio should stop playing.</p>
  587. <p>Default is <code>0</code>.</p>
  588. </td>
  589. </tr>
  590. </tbody>
  591. </table>
  592. <dl class="details">
  593. <dt class="tag-returns"><strong>Returns:</strong> A reference to this instance.</dt>
  594. </dl>
  595. </div>
  596. <h2 class="subsection-title">Source</h2>
  597. <p>
  598. <a href="https://github.com/mrdoob/three.js/blob/master/src/audio/Audio.js" translate="no" target="_blank" rel="noopener">src/audio/Audio.js</a>
  599. </p>
  600. </article>
  601. </section>
  602. <script src="../scripts/linenumber.js"></script>
  603. <script src="../scripts/page.js"></script>
  604. </body>
  605. </html>
粤ICP备19079148号