Bug 1070216 - Make it possible to disable AudioStreamAnalyser's debug canvas. r=padenot

This commit is contained in:
Andreas Pehrson 2015-10-15 01:08:33 +08:00
parent b24fa7a566
commit e37775a762

View File

@ -56,7 +56,7 @@ AudioStreamAnalyser.prototype = {
* Useful to debug tests.
*/
enableDebugCanvas: function() {
var cvs = document.createElement("canvas");
var cvs = this.debugCanvas = document.createElement("canvas");
document.getElementById("content").appendChild(cvs);
// Easy: 1px per bin
@ -73,11 +73,26 @@ AudioStreamAnalyser.prototype = {
for (var i = 0; i < array.length; i++) {
c.fillRect(i, (256 - (array[i])), 1, 256);
}
requestAnimationFrame(render);
if (!cvs.stopDrawing) {
requestAnimationFrame(render);
}
}
requestAnimationFrame(render);
},
/**
* Stop drawing of and remove the debug canvas from the DOM if it was
* previously added.
*/
disableDebugCanvas: function() {
if (!this.debugCanvas || !this.debugCanvas.parentElement) {
return;
}
this.debugCanvas.stopDrawing = true;
this.debugCanvas.parentElement.removeChild(this.debugCanvas);
},
/**
* Return a Promise, that will be resolved when the function passed as
* argument, when called, returns true (meaning the analysis was a