You can not select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
			
				
					98 lines
				
				2.6 KiB
			
		
		
			
		
	
	
					98 lines
				
				2.6 KiB
			| 
								 
											3 years ago
										 
									 | 
							
								<!DOCTYPE html>
							 | 
						||
| 
								 | 
							
								<html lang="zh">
							 | 
						||
| 
								 | 
							
									<head>
							 | 
						||
| 
								 | 
							
										<meta charset="utf-8" />
							 | 
						||
| 
								 | 
							
										<base href="../../../" />
							 | 
						||
| 
								 | 
							
										<script src="page.js"></script>
							 | 
						||
| 
								 | 
							
										<link type="text/css" rel="stylesheet" href="page.css" />
							 | 
						||
| 
								 | 
							
									</head>
							 | 
						||
| 
								 | 
							
									<body>
							 | 
						||
| 
								 | 
							
										[page:Loader] →
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h1>[name]</h1>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<p class="desc">
							 | 
						||
| 
								 | 
							
											用来加载
							 | 
						||
| 
								 | 
							
											[link:https://developer.mozilla.org/en-US/docs/Web/API/AudioBuffer AudioBuffer]的一个类。
							 | 
						||
| 
								 | 
							
											内部默认使用[page:FileLoader]来加载文件。
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h2>代码示例</h2>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<code>
							 | 
						||
| 
								 | 
							
										// 初始化一个监听
							 | 
						||
| 
								 | 
							
										const audioListener = new THREE.AudioListener();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										// 把监听添加到camera
							 | 
						||
| 
								 | 
							
										camera.add( audioListener );
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										// 初始化音频对象
							 | 
						||
| 
								 | 
							
										const oceanAmbientSound = new THREE.Audio( audioListener );
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										// 添加一个音频对象到场景中
							 | 
						||
| 
								 | 
							
										scene.add( oceanAmbientSound );
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										// 初始化一个加载器
							 | 
						||
| 
								 | 
							
										const loader = new THREE.AudioLoader();
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										// 加载资源
							 | 
						||
| 
								 | 
							
										loader.load(
							 | 
						||
| 
								 | 
							
											// 资源URL
							 | 
						||
| 
								 | 
							
											'audio/ambient_ocean.ogg',
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
											// onLoad回调
							 | 
						||
| 
								 | 
							
											function ( audioBuffer ) {
							 | 
						||
| 
								 | 
							
												// 给一个加载器对象设置音频对象的缓存
							 | 
						||
| 
								 | 
							
												oceanAmbientSound.setBuffer( audioBuffer );
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
												// 播放音频
							 | 
						||
| 
								 | 
							
												oceanAmbientSound.play();
							 | 
						||
| 
								 | 
							
											},
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
											// onProgress回调
							 | 
						||
| 
								 | 
							
											function ( xhr ) {
							 | 
						||
| 
								 | 
							
												console.log( (xhr.loaded / xhr.total * 100) + '% loaded' );
							 | 
						||
| 
								 | 
							
											},
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
											// onError回调
							 | 
						||
| 
								 | 
							
											function ( err ) {
							 | 
						||
| 
								 | 
							
												console.log( 'An error happened' );
							 | 
						||
| 
								 | 
							
											}
							 | 
						||
| 
								 | 
							
										);
							 | 
						||
| 
								 | 
							
										</code>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h2>构造函数</h2>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h3>[name]( [param:LoadingManager manager] )</h3>
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
										[page:LoadingManager manager] — 加载器使用的[page:LoadingManager loadingManager]。默认为[page:LoadingManager THREE.DefaultLoadingManager].<br /><br />
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										创建一个新的[name].
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h2>属性</h2>
							 | 
						||
| 
								 | 
							
										<p>共有属性请参见其基类[page:Loader]。</p>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h2>方法</h2>
							 | 
						||
| 
								 | 
							
										<p>共有方法请参见其基类[page:Loader]。</p>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h3>[method:undefined load]( [param:String url], [param:Function onLoad], [param:Function onProgress], [param:Function onError] )</h3>
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
										[page:String url] — 文件的URL或者路径,也可以为
							 | 
						||
| 
								 | 
							
											[link:https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/Data_URIs Data URI].<br />
							 | 
						||
| 
								 | 
							
										[page:Function onLoad] — 加载完成时将调用。回调参数为将要加载的响应文本。<br />
							 | 
						||
| 
								 | 
							
										[page:Function onProgress] —   将在加载过程中进行调用。参数为XMLHttpRequest实例,实例包含[page:Integer total]和[page:Integer loaded]字节.<br />
							 | 
						||
| 
								 | 
							
										[page:Function onError] — 在加载错误时被调用。<br />
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
											从URL中进行加载并将已经加载的[page:String AudioBuffer]传递给onLoad。
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<h2>源</h2>
							 | 
						||
| 
								 | 
							
								
							 | 
						||
| 
								 | 
							
										<p>
							 | 
						||
| 
								 | 
							
											[link:https://github.com/mrdoob/three.js/blob/master/src/[path].js src/[path].js]
							 | 
						||
| 
								 | 
							
										</p>
							 | 
						||
| 
								 | 
							
									</body>
							 | 
						||
| 
								 | 
							
								</html>
							 |