diff ape.js @ 113:dcb042ed9d76

Fix Bug #1241 and #1213: Added checks each time new test page is loaded that all audioObjects have decoded. Writes to browser console WAIT and does not issue any play command if any audioObjects not ready.
author Nicholas Jillings <n.g.r.jillings@se14.qmul.ac.uk>
date Mon, 25 May 2015 11:14:12 +0100
parents 4d8846186db4
children d9a02dbfbf2c
line wrap: on
line diff
--- a/ape.js	Mon May 25 10:06:28 2015 +0100
+++ b/ape.js	Mon May 25 11:14:12 2015 +0100
@@ -265,8 +265,7 @@
 {
 	
 	// Reset audioEngineContext.Metric globals for new test
-	audioEngineContext.metric.lastClicked = -1;
-	audioEngineContext.metric.data = -1;
+	audioEngineContext.newTestPage();
 	
 	// Used to load a specific test page
 	var textXML = testXMLSetups[id];
@@ -341,37 +340,6 @@
 	loopPlayback = false;
 	// Create AudioEngine bindings for playback
 	if (loopPlayback) {
-		audioEngineContext.play = function() {
-			// Send play command to all playback buffers for synchronised start
-			// Also start timer callbacks to detect if playback has finished
-			if (this.status == 0) {
-				this.timer.startTest();
-				// First get current clock
-				var timer = audioContext.currentTime;
-				// Add 3 seconds
-				timer += 3.0;
-				// Send play to all tracks
-				for (var i=0; i<this.audioObjects.length; i++)
-				{
-					this.audioObjects[i].play(timer);
-				}
-				this.status = 1;
-			}
-		};
-		
-		audioEngineContext.stop = function() {
-			// Send stop and reset command to all playback buffers
-			if (this.status == 1) {
-				if (this.loopPlayback) {
-					for (var i=0; i<this.audioObjects.length; i++)
-					{
-						this.audioObjects[i].stop();
-					}
-				}
-				this.status = 0;
-			}
-		};
-		
 		audioEngineContext.selectedTrack = function(id) {
 			for (var i=0; i<this.audioObjects.length; i++)
 			{
@@ -383,26 +351,6 @@
 			}
 		};
 	} else {
-		audioEngineContext.play = function() {
-			// Send play command to all playback buffers for synchronised start
-			// Also start timer callbacks to detect if playback has finished
-			if (this.status == 0) {
-				this.timer.startTest();
-				this.status = 1;
-			}
-		};
-		
-		audioEngineContext.stop = function() {
-			// Send stop and reset command to all playback buffers
-			if (this.status == 1) {
-				for (var i=0; i<this.audioObjects.length; i++)
-				{
-					this.audioObjects[i].stop();
-				}
-				this.status = 0;
-			}
-		};
-		
 		audioEngineContext.selectedTrack = function(id) {
 			for (var i=0; i<this.audioObjects.length; i++)
 			{
@@ -753,7 +701,7 @@
 		var testId = currentState.substr(8,currentState.length-7);
 		// Check if we have any post tests to perform
 		var postXML = $(testXMLSetups[testId]).find('PostTest')[0];
-		if (postXML == undefined) {
+		if (postXML == undefined || postXML.childElementCount == 0) {
 			testEnded(testId);
 		}
 		else if (postXML.childElementCount > 0)