提交 21844b4c 编写于 作者: M Matthew Tung

Use source.onended for handling the 'ended' event (in response to the audio...

Use source.onended for handling the 'ended' event (in response to the audio track finishing playback)
上级 15ecabbc
......@@ -12,6 +12,7 @@ THREE.Audio = function ( listener, autoplay ) {
this.context = listener.context;
this.source = this.context.createBufferSource();
this.source.onended = this.onEnded.bind(this);
this.gain = this.context.createGain();
this.gain.connect( this.context.destination );
......@@ -59,6 +60,7 @@ THREE.Audio.prototype.play = function () {
source.buffer = this.source.buffer;
source.loop = this.source.loop;
source.onended = this.source.onended;
source.connect( this.panner );
source.start( 0, this.startTime );
......@@ -80,7 +82,6 @@ THREE.Audio.prototype.pause = function () {
this.source.stop();
this.startTime = this.context.currentTime;
this.isPlaying = false;
};
......@@ -88,6 +89,11 @@ THREE.Audio.prototype.stop = function () {
this.source.stop();
this.startTime = 0;
};
THREE.Audio.prototype.onEnded = function() {
this.isPlaying = false;
};
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册