@@ -13,7 +13,7 @@ THREE.Audio = function ( listener ) {
1313 this . source . onended = this . onEnded . bind ( this ) ;
1414
1515 this . gain = this . context . createGain ( ) ;
16- this . gain . connect ( listener . getOutputNode ( ) ) ;
16+ this . gain . connect ( listener . getOutputNode ( ) ) ;
1717
1818 this . autoplay = false ;
1919
@@ -29,37 +29,38 @@ THREE.Audio = function ( listener ) {
2929THREE . Audio . prototype = Object . create ( THREE . Object3D . prototype ) ;
3030THREE . Audio . prototype . constructor = THREE . Audio ;
3131
32- THREE . Audio . prototype . getOutput = function ( ) {
32+ THREE . Audio . prototype . getOutput = function ( ) {
33+
3334 return this . gain ;
35+
3436} ;
3537
36- THREE . Audio . prototype . load = function ( fileName ) {
38+ THREE . Audio . prototype . load = function ( file ) {
39+
40+ var buffer = new THREE . AudioBuffer ( this . context ) ;
41+ buffer . load ( file ) ;
42+
43+ this . setBuffer ( buffer ) ;
3744
38- var audioBuffer = new THREE . AudioBuffer ( this . context ) ;
39- audioBuffer . load ( fileName ) ;
40- this . setBuffer ( audioBuffer ) ;
4145 return this ;
4246
4347} ;
4448
45-
4649THREE . Audio . prototype . setNodeSource = function ( audioNode ) {
4750
4851 this . hasPlaybackControl = false ;
4952 this . sourceType = 'audioNode' ;
5053 this . source = audioNode ;
5154 this . connect ( ) ;
52-
55+
5356 return this ;
5457
5558} ;
5659
57-
58-
5960THREE . Audio . prototype . setBuffer = function ( audioBuffer ) {
6061
6162 var scope = this ;
62-
63+
6364 audioBuffer . onReady ( function ( buffer ) {
6465 scope . source . buffer = buffer ;
6566 scope . sourceType = 'buffer' ;
@@ -70,8 +71,6 @@ THREE.Audio.prototype.setBuffer = function ( audioBuffer ) {
7071
7172} ;
7273
73-
74-
7574THREE . Audio . prototype . play = function ( ) {
7675
7776 if ( this . isPlaying === true ) {
@@ -80,15 +79,14 @@ THREE.Audio.prototype.play = function () {
8079 return ;
8180
8281 }
83-
82+
8483 if ( this . hasPlaybackControl === false ) {
8584
8685 console . warn ( 'THREE.Audio: this Audio has no playback control.' ) ;
8786 return ;
8887
8988 }
9089
91-
9290 var source = this . context . createBufferSource ( ) ;
9391
9492 source . buffer = this . source . buffer ;
@@ -107,25 +105,25 @@ THREE.Audio.prototype.play = function () {
107105
108106THREE . Audio . prototype . pause = function ( ) {
109107
110- if ( this . hasPlaybackControl === false ) {
111-
108+ if ( this . hasPlaybackControl === false ) {
109+
112110 console . warn ( 'THREE.Audio: this Audio has no playback control.' ) ;
113111 return ;
114-
112+
115113 }
116-
114+
117115 this . source . stop ( ) ;
118116 this . startTime = this . context . currentTime ;
119117
120118} ;
121119
122120THREE . Audio . prototype . stop = function ( ) {
123121
124- if ( this . hasPlaybackControl === false ) {
125-
122+ if ( this . hasPlaybackControl === false ) {
123+
126124 console . warn ( 'THREE.Audio: this Audio has no playback control.' ) ;
127125 return ;
128-
126+
129127 }
130128
131129 this . source . stop ( ) ;
@@ -138,11 +136,11 @@ THREE.Audio.prototype.connect = function () {
138136 if ( this . filter !== null ) {
139137
140138 this . source . connect ( this . filter ) ;
141- this . filter . connect ( this . getOutput ( ) ) ;
139+ this . filter . connect ( this . getOutput ( ) ) ;
142140
143141 } else {
144142
145- this . source . connect ( this . getOutput ( ) ) ;
143+ this . source . connect ( this . getOutput ( ) ) ;
146144
147145 }
148146
@@ -153,11 +151,11 @@ THREE.Audio.prototype.disconnect = function () {
153151 if ( this . filter !== null ) {
154152
155153 this . source . disconnect ( this . filter ) ;
156- this . filter . disconnect ( this . getOutput ( ) ) ;
154+ this . filter . disconnect ( this . getOutput ( ) ) ;
157155
158156 } else {
159157
160- this . source . disconnect ( this . getOutput ( ) ) ;
158+ this . source . disconnect ( this . getOutput ( ) ) ;
161159
162160 }
163161
@@ -187,11 +185,11 @@ THREE.Audio.prototype.getFilter = function () {
187185
188186THREE . Audio . prototype . setPlaybackRate = function ( value ) {
189187
190- if ( this . hasPlaybackControl === false ) {
191-
188+ if ( this . hasPlaybackControl === false ) {
189+
192190 console . warn ( 'THREE.Audio: this Audio has no playback control.' ) ;
193191 return ;
194-
192+
195193 }
196194
197195 this . playbackRate = value ;
@@ -218,24 +216,24 @@ THREE.Audio.prototype.onEnded = function() {
218216
219217THREE . Audio . prototype . setLoop = function ( value ) {
220218
221- if ( this . hasPlaybackControl === false ) {
222-
219+ if ( this . hasPlaybackControl === false ) {
220+
223221 console . warn ( 'THREE.Audio: this Audio has no playback control.' ) ;
224222 return ;
225-
223+
226224 }
227225
228226 this . source . loop = value ;
229227
230228} ;
231229
232230THREE . Audio . prototype . getLoop = function ( ) {
233-
234- if ( this . hasPlaybackControl === false ) {
235-
231+
232+ if ( this . hasPlaybackControl === false ) {
233+
236234 console . warn ( 'THREE.Audio: this Audio has no playback control.' ) ;
237235 return false ;
238-
236+
239237 }
240238
241239 return this . source . loop ;
@@ -254,4 +252,3 @@ THREE.Audio.prototype.getVolume = function () {
254252 return this . gain . gain . value ;
255253
256254} ;
257-
0 commit comments