diff core.js @ 1617:ed5b4a9b266a

Possible fix for Bug #1238. audioObject metric collection now controlled by the audioObjects themselves for timer information. Lastclicked and sliderPlayed functions no longer used.
author Nicholas Jillings <nickjillings@users.noreply.github.com>
date Sun, 24 May 2015 11:33:04 +0100
parents 4f3ddd805ff3
children 05e7edb032b9
line wrap: on
line diff
--- a/core.js	Sun May 24 10:51:41 2015 +0100
+++ b/core.js	Sun May 24 11:33:04 2015 +0100
@@ -175,9 +175,16 @@
 	
 	this.play = function(startTime) {
 		this.bufferNode = audioContext.createBufferSource();
+		this.bufferNode.owner = this;
 		this.bufferNode.connect(this.outputGain);
 		this.bufferNode.buffer = this.buffer;
 		this.bufferNode.loop = audioEngineContext.loopPlayback;
+		if (this.bufferNode.loop == false) {
+			this.bufferNode.onended = function() {
+				this.owner.metric.listening(audioEngineContext.timer.getTestTime());
+			}
+		}
+		this.metric.listening(audioEngineContext.timer.getTestTime());
 		this.bufferNode.start(startTime);
 		this.played = true;
 	};
@@ -187,6 +194,7 @@
 		{
 			this.bufferNode.stop(0);
 			this.bufferNode = undefined;
+			this.metric.listening(audioEngineContext.timer.getTestTime());
 		}
 	};
 
@@ -278,6 +286,7 @@
 	
 	this.listenedTimer = 0;
 	this.listenStart = 0;
+	this.listenHold = false;
 	this.initialPosition = -1;
 	this.movementTracker = [];
 	this.wasListenedTo = false;
@@ -299,13 +308,15 @@
 	
 	this.listening = function(time)
 	{
-		if (this.listenStart == 0)
+		if (this.listenHold == false)
 		{
 			this.wasListenedTo = true;
 			this.listenStart = time;
+			this.listenHold = true;
 		} else {
 			this.listenedTimer += (time - this.listenStart);
 			this.listenStart = 0;
+			this.listenHold = false;
 		}
 	};
 }