Audio.html 6.4 KB
Newer Older
L
Lewy Blue 已提交
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
<!DOCTYPE html>
<html lang="en">
	<head>
		<meta charset="utf-8" />
		<base href="../../" />
		<script src="list.js"></script>
		<script src="page.js"></script>
		<link type="text/css" rel="stylesheet" href="page.css" />
	</head>
	<body>
		[page:Object3D] &rarr;

		<h1>[name]</h1>

		<div class="desc">
			Create a non-positional ( global ) audio object.<br /><br />

			This uses the [link:https://developer.mozilla.org/en-US/docs/Web/API/Web_Audio_API Web Audio API].
		</div>


		<h2>Example</h2>

		<div>[example:misc_sound misc / sound ]</div>
		<code>
		//Create an AudioListener and add it to the camera
		var listener = new THREE.AudioListener();
		camera.add( listener );

		// create a global audio source
		var sound = new THREE.Audio( listener );

		var audioLoader = new THREE.AudioLoader();

		//Load a sound and set it as the Audio object's buffer
		audioLoader.load( 'sounds/ambient.ogg', function( buffer ) {
			sound.setBuffer( buffer );
M
Mugen87 已提交
38 39
			sound.setLoop( true );
			sound.setVolume( 0.5 );
L
Lewy Blue 已提交
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79
			sound.play();
		});
		</code>


		<h2>Constructor</h2>


		<h3>[name]( [page:AudioListener listener] )</h3>
		<div>
		listener — (required) [page:AudioListener AudioListener] instance.
		</div>


		<h2>Properties</h2>

		<h3>[property:Boolean autoplay]</h3>
		<div>Whether to start playback automatically. Default is *false*.</div>

		<h3>[property:AudioContext context]</h3>
		<div>The [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext AudioContext] of the [page:AudioListener listener] given in the constructor.</div>

		<h3>[property:Array filters]</h3>
		<div>Whether the audio is currently playing. Default is empty array.</div>

		<h3>[property:GainNode gain]</h3>
		<div>A [link:https://developer.mozilla.org/en-US/docs/Web/API/GainNode GainNode] created
		using [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createGain AudioContext.createGain]().</div>

		<h3>[property:Boolean hasPlaybackControl]</h3>
		<div>Whether playback can be controlled using the [page:Audio.play play](),
			[page:Audio.pause pause]() etc. methods. Default is *true*.</div>

		<h3>[property:Number playbackRate]</h3>
		<div>Speed of playback. Default is *1*.</div>

		<h3>[property:Boolean isPlaying]</h3>
		<div>Whether the audio is currently playing.</div>

		<h3>[property:Number startTime]</h3>
M
Mugen87 已提交
80 81 82 83
		<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>

		<h3>[property:Number offset]</h3>
		<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>
L
Lewy Blue 已提交
84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206

		<h3>[property:String source]</h3>
		<div>An [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode AudioBufferSourceNode] created
		using [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioContext/createBufferSource AudioContext.createBufferSource]().</div>

		<h3>[property:String sourceType]</h3>
		<div>Type of the audio source. Default is string 'empty'.</div>

		<h3>[property:String type]</h3>
		<div>String denoting the type, set to 'Audio'.</div>


		<h2>Methods</h2>

		<h3>[method:null connect]()</h3>
		<div>
		Connect to the [page:Audio.source]. This is used internally on initialisation and when
		setting / removing filters.
		</div>

		<h3>[method:null disconnect]()</h3>
		<div>
		Disconnect from the [page:Audio.source]. This is used internally when
		setting / removing filters.
		</div>

		<h3>[method:Array getFilter]()</h3>
		<div>
		Returns the first element of the [page:Audio.filters filters] array.
		</div>

		<h3>[method:null getFilters]()</h3>
		<div>
		Returns the [page:Audio.filters filters] array.
		</div>

		<h3>[method:Boolean getLoop]()</h3>
		<div>
		Return the value of [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop]
		 (whether playback should loop).
		</div>

		<h3>[method:GainNode getOutput]()</h3>
		<div>
		Return the [page:Audio.gain gainNode].
		</div>

		<h3>[method:Number getPlaybackRate]()</h3>
		<div>
		Return the value of [page:Audio.playbackRate playbackRate].
		</div>

		<h3>[method:Number getVolume]( value )</h3>
		<div>
		Return the current volume.
		</div>

		<h3>[method:null play]()</h3>
		<div>
		If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, starts playback.
		</div>

		<h3>[method:null pause]()</h3>
		<div>
		If [page:Audio.hasPlaybackControl hasPlaybackControl] is true, pauses playback.
		</div>

		<h3>[method:null onEnded]()</h3>
		<div>
		Called automatically when playback finished. Sets If [page:Audio.isPlaying isPlaying] to false.
		</div>

		<h3>[method:Audio setBuffer]( audioBuffer )</h3>
		<div>
		Setup the [page:Audio.source source] to the audioBuffer, and sets [page:Audio.sourceType sourceType] to 'buffer'.<br />
		If [page:Audio.autoplay autoplay], also starts playback.
		</div>

		<h3>[method:null setFilter]( filter )</h3>
		<div>
		Add the filter to the [page:Audio.filters filters] array.
		</div>

		<h3>[method:Audio setFilters]( [page:Array value] )</h3>
		<div>
		value - arrays of filters.<br />
		Set the [page:Audio.filters filters] array to *value*.
		</div>

		<h3>[method:null setLoop]( [page:Boolean value] )</h3>
		<div>
		Set [link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBufferSourceNode/loop source.loop] to *value*
		(whether playback should loop).
		</div>

		<h3>[method:null setNodeSource]( audioNode )</h3>
		<div>
		Setup the [page:Audio.source source] to the audioBuffer, and sets [page:Audio.sourceType sourceType] to 'audioNode'.<br />
		Also sets [page:Audio.hasPlaybackControl hasPlaybackControl] to false.

		</div>

		<h3>[method:null setPlaybackRate]( [page:Number value] )</h3>
		<div>
		If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, set the [page:Audio.playbackRate playbackRate] to *value*.
		</div>

		<h3>[method:null setVolume]( [page:Number value] )</h3>
		<div>
		Set the volume.
		</div>

		<h3>[method:null stop]()</h3>
		<div>
		If [page:Audio.hasPlaybackControl hasPlaybackControl] is enabled, stops playback,
		resets [page:Audio.startTime startTime] to *0* and sets [page:Audio.isPlaying isPlaying] to false.
		</div>

		<h2>Source</h2>

		[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
	</body>
</html>