|
@@ -28,218 +28,221 @@ THREE.Audio = function ( listener ) {
|
|
|
|
|
|
};
|
|
|
|
|
|
-THREE.Audio.prototype = Object.create( THREE.Object3D.prototype );
|
|
|
-THREE.Audio.prototype.constructor = THREE.Audio;
|
|
|
+THREE.Audio.prototype = Object.assign( Object.create( THREE.Object3D.prototype ), {
|
|
|
|
|
|
-THREE.Audio.prototype.getOutput = function () {
|
|
|
+ constructor: THREE.Audio,
|
|
|
|
|
|
- return this.gain;
|
|
|
+ getOutput: function () {
|
|
|
|
|
|
-};
|
|
|
+ return this.gain;
|
|
|
|
|
|
-THREE.Audio.prototype.setNodeSource = function ( audioNode ) {
|
|
|
+ },
|
|
|
|
|
|
- this.hasPlaybackControl = false;
|
|
|
- this.sourceType = 'audioNode';
|
|
|
- this.source = audioNode;
|
|
|
- this.connect();
|
|
|
+ setNodeSource: function ( audioNode ) {
|
|
|
|
|
|
- return this;
|
|
|
+ this.hasPlaybackControl = false;
|
|
|
+ this.sourceType = 'audioNode';
|
|
|
+ this.source = audioNode;
|
|
|
+ this.connect();
|
|
|
|
|
|
-};
|
|
|
+ return this;
|
|
|
|
|
|
-THREE.Audio.prototype.setBuffer = function ( audioBuffer ) {
|
|
|
+ },
|
|
|
|
|
|
- var scope = this;
|
|
|
+ setBuffer: function ( audioBuffer ) {
|
|
|
|
|
|
- scope.source.buffer = audioBuffer;
|
|
|
- scope.sourceType = 'buffer';
|
|
|
- if ( scope.autoplay ) scope.play();
|
|
|
+ var scope = this;
|
|
|
|
|
|
- return this;
|
|
|
+ scope.source.buffer = audioBuffer;
|
|
|
+ scope.sourceType = 'buffer';
|
|
|
+ if ( scope.autoplay ) scope.play();
|
|
|
|
|
|
-};
|
|
|
+ return this;
|
|
|
|
|
|
-THREE.Audio.prototype.play = function () {
|
|
|
+ },
|
|
|
|
|
|
- if ( this.isPlaying === true ) {
|
|
|
+ play: function () {
|
|
|
|
|
|
- console.warn( 'THREE.Audio: Audio is already playing.' );
|
|
|
- return;
|
|
|
+ if ( this.isPlaying === true ) {
|
|
|
|
|
|
- }
|
|
|
+ console.warn( 'THREE.Audio: Audio is already playing.' );
|
|
|
+ return;
|
|
|
|
|
|
- if ( this.hasPlaybackControl === false ) {
|
|
|
+ }
|
|
|
|
|
|
- console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
|
|
- return;
|
|
|
+ if ( this.hasPlaybackControl === false ) {
|
|
|
|
|
|
- }
|
|
|
+ console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
|
|
+ return;
|
|
|
|
|
|
- var source = this.context.createBufferSource();
|
|
|
+ }
|
|
|
|
|
|
- source.buffer = this.source.buffer;
|
|
|
- source.loop = this.source.loop;
|
|
|
- source.onended = this.source.onended;
|
|
|
- source.start( 0, this.startTime );
|
|
|
- source.playbackRate.value = this.playbackRate;
|
|
|
+ var source = this.context.createBufferSource();
|
|
|
|
|
|
- this.isPlaying = true;
|
|
|
+ source.buffer = this.source.buffer;
|
|
|
+ source.loop = this.source.loop;
|
|
|
+ source.onended = this.source.onended;
|
|
|
+ source.start( 0, this.startTime );
|
|
|
+ source.playbackRate.value = this.playbackRate;
|
|
|
|
|
|
- this.source = source;
|
|
|
+ this.isPlaying = true;
|
|
|
|
|
|
- this.connect();
|
|
|
+ this.source = source;
|
|
|
|
|
|
-};
|
|
|
+ this.connect();
|
|
|
|
|
|
-THREE.Audio.prototype.pause = function () {
|
|
|
+ },
|
|
|
|
|
|
- if ( this.hasPlaybackControl === false ) {
|
|
|
+ pause: function () {
|
|
|
|
|
|
- console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
|
|
- return;
|
|
|
+ if ( this.hasPlaybackControl === false ) {
|
|
|
|
|
|
- }
|
|
|
+ console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
|
|
+ return;
|
|
|
|
|
|
- this.source.stop();
|
|
|
- this.startTime = this.context.currentTime;
|
|
|
+ }
|
|
|
|
|
|
-};
|
|
|
+ this.source.stop();
|
|
|
+ this.startTime = this.context.currentTime;
|
|
|
|
|
|
-THREE.Audio.prototype.stop = function () {
|
|
|
+ },
|
|
|
|
|
|
- if ( this.hasPlaybackControl === false ) {
|
|
|
+ stop: function () {
|
|
|
|
|
|
- console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
|
|
- return;
|
|
|
+ if ( this.hasPlaybackControl === false ) {
|
|
|
|
|
|
- }
|
|
|
+ console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
|
|
+ return;
|
|
|
|
|
|
- this.source.stop();
|
|
|
- this.startTime = 0;
|
|
|
+ }
|
|
|
|
|
|
-};
|
|
|
+ this.source.stop();
|
|
|
+ this.startTime = 0;
|
|
|
|
|
|
-THREE.Audio.prototype.connect = function () {
|
|
|
+ },
|
|
|
|
|
|
- if ( this.filter !== null ) {
|
|
|
+ connect: function () {
|
|
|
|
|
|
- this.source.connect( this.filter );
|
|
|
- this.filter.connect( this.getOutput() );
|
|
|
+ if ( this.filter !== null ) {
|
|
|
|
|
|
- } else {
|
|
|
+ this.source.connect( this.filter );
|
|
|
+ this.filter.connect( this.getOutput() );
|
|
|
|
|
|
- this.source.connect( this.getOutput() );
|
|
|
+ } else {
|
|
|
|
|
|
- }
|
|
|
+ this.source.connect( this.getOutput() );
|
|
|
|
|
|
-};
|
|
|
+ }
|
|
|
|
|
|
-THREE.Audio.prototype.disconnect = function () {
|
|
|
+ },
|
|
|
|
|
|
- if ( this.filter !== null ) {
|
|
|
+ disconnect: function () {
|
|
|
|
|
|
- this.source.disconnect( this.filter );
|
|
|
- this.filter.disconnect( this.getOutput() );
|
|
|
+ if ( this.filter !== null ) {
|
|
|
|
|
|
- } else {
|
|
|
+ this.source.disconnect( this.filter );
|
|
|
+ this.filter.disconnect( this.getOutput() );
|
|
|
|
|
|
- this.source.disconnect( this.getOutput() );
|
|
|
+ } else {
|
|
|
|
|
|
- }
|
|
|
+ this.source.disconnect( this.getOutput() );
|
|
|
|
|
|
-};
|
|
|
+ }
|
|
|
|
|
|
-THREE.Audio.prototype.getFilter = function () {
|
|
|
+ },
|
|
|
|
|
|
- return this.filter;
|
|
|
+ getFilter: function () {
|
|
|
|
|
|
-};
|
|
|
+ return this.filter;
|
|
|
|
|
|
-THREE.Audio.prototype.setFilter = function ( value ) {
|
|
|
+ },
|
|
|
|
|
|
- if ( value === undefined ) value = null;
|
|
|
+ setFilter: function ( value ) {
|
|
|
|
|
|
- if ( this.isPlaying === true ) {
|
|
|
+ if ( value === undefined ) value = null;
|
|
|
|
|
|
- this.disconnect();
|
|
|
- this.filter = value;
|
|
|
- this.connect();
|
|
|
+ if ( this.isPlaying === true ) {
|
|
|
|
|
|
- } else {
|
|
|
+ this.disconnect();
|
|
|
+ this.filter = value;
|
|
|
+ this.connect();
|
|
|
|
|
|
- this.filter = value;
|
|
|
+ } else {
|
|
|
|
|
|
- }
|
|
|
+ this.filter = value;
|
|
|
|
|
|
-};
|
|
|
+ }
|
|
|
|
|
|
-THREE.Audio.prototype.setPlaybackRate = function ( value ) {
|
|
|
+ },
|
|
|
|
|
|
- if ( this.hasPlaybackControl === false ) {
|
|
|
+ setPlaybackRate: function ( value ) {
|
|
|
|
|
|
- console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
|
|
- return;
|
|
|
+ if ( this.hasPlaybackControl === false ) {
|
|
|
|
|
|
- }
|
|
|
+ console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
|
|
+ return;
|
|
|
|
|
|
- this.playbackRate = value;
|
|
|
+ }
|
|
|
|
|
|
- if ( this.isPlaying === true ) {
|
|
|
+ this.playbackRate = value;
|
|
|
|
|
|
- this.source.playbackRate.value = this.playbackRate;
|
|
|
+ if ( this.isPlaying === true ) {
|
|
|
|
|
|
- }
|
|
|
+ this.source.playbackRate.value = this.playbackRate;
|
|
|
|
|
|
-};
|
|
|
+ }
|
|
|
|
|
|
-THREE.Audio.prototype.getPlaybackRate = function () {
|
|
|
+ },
|
|
|
|
|
|
- return this.playbackRate;
|
|
|
+ getPlaybackRate: function () {
|
|
|
|
|
|
-};
|
|
|
+ return this.playbackRate;
|
|
|
|
|
|
-THREE.Audio.prototype.onEnded = function () {
|
|
|
+ },
|
|
|
|
|
|
- this.isPlaying = false;
|
|
|
+ onEnded: function () {
|
|
|
|
|
|
-};
|
|
|
+ this.isPlaying = false;
|
|
|
|
|
|
-THREE.Audio.prototype.setLoop = function ( value ) {
|
|
|
+ },
|
|
|
|
|
|
- if ( this.hasPlaybackControl === false ) {
|
|
|
+ getLoop: function () {
|
|
|
|
|
|
- console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
|
|
- return;
|
|
|
+ if ( this.hasPlaybackControl === false ) {
|
|
|
|
|
|
- }
|
|
|
+ console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
|
|
+ return false;
|
|
|
|
|
|
- this.source.loop = value;
|
|
|
+ }
|
|
|
|
|
|
-};
|
|
|
+ return this.source.loop;
|
|
|
|
|
|
-THREE.Audio.prototype.getLoop = function () {
|
|
|
+ },
|
|
|
|
|
|
- if ( this.hasPlaybackControl === false ) {
|
|
|
+ setLoop: function ( value ) {
|
|
|
|
|
|
- console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
|
|
- return false;
|
|
|
+ if ( this.hasPlaybackControl === false ) {
|
|
|
|
|
|
- }
|
|
|
+ console.warn( 'THREE.Audio: this Audio has no playback control.' );
|
|
|
+ return;
|
|
|
|
|
|
- return this.source.loop;
|
|
|
+ }
|
|
|
|
|
|
-};
|
|
|
+ this.source.loop = value;
|
|
|
|
|
|
+ },
|
|
|
|
|
|
-THREE.Audio.prototype.setVolume = function ( value ) {
|
|
|
+ getVolume: function () {
|
|
|
|
|
|
- this.gain.gain.value = value;
|
|
|
+ return this.gain.gain.value;
|
|
|
|
|
|
-};
|
|
|
+ },
|
|
|
|
|
|
-THREE.Audio.prototype.getVolume = function () {
|
|
|
|
|
|
- return this.gain.gain.value;
|
|
|
+ setVolume: function ( value ) {
|
|
|
|
|
|
-};
|
|
|
+ this.gain.gain.value = value;
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+} );
|