浏览代码

Use source.onended for handling the 'ended' event (in response to the audio track finishing playback)

Matthew Tung 10 年之前
父节点
当前提交
21844b4c94
共有 1 个文件被更改,包括 7 次插入1 次删除
  1. 7 1
      src/extras/audio/Audio.js

+ 7 - 1
src/extras/audio/Audio.js

@@ -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;
 
 };