From d8d24b964e4996b872b61b8687f617213b2ed8f7 Mon Sep 17 00:00:00 2001 From: Paul Nicholls Date: Wed, 3 Dec 2014 16:29:32 +1300 Subject: [PATCH] Move callback processing to new "save" button. --- js/recordmp3.js | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/js/recordmp3.js b/js/recordmp3.js index a6a408c..6f607f2 100644 --- a/js/recordmp3.js +++ b/js/recordmp3.js @@ -15,6 +15,7 @@ var btnPlay = document.createElement('button'); var btnRecord = document.createElement('button'); var btnStop = document.createElement('button'); + var btnSave = document.createElement('button'); if (!config.element) { __log('No element specified. Cannot initialise recorder.'); return; @@ -92,6 +93,7 @@ } btnStop.disabled = true; btnRecord.disabled = false; + btnSave.disabled = false; } this.stopRecording = function(){ @@ -125,6 +127,15 @@ } } + this.save = function(){ + if (self.outputFormat === 'mp3') { + self.convertToMP3(); + } else { + // Assume WAV. + window[self.callback](self.audioData); + } + } + this.clear = function(){ worker.postMessage({ command: 'clear' }); } @@ -146,12 +157,6 @@ var blob = e.data; self.audioData = blob; btnPlay.disabled = false; - if (self.outputFormat === 'mp3') { - self.convertToMP3(); - } else { - // Assume WAV. - window[self.callback](blob); - } } this.convertToMP3 = function() { @@ -272,9 +277,14 @@ btnPlay.className = 'btn-play'; btnPlay.innerHTML = 'play'; btnPlay.disabled = true; + btnSave.onclick = this.save; + btnSave.className = 'btn-save'; + btnSave.innerHTML = 'save'; + btnSave.disabled = true; config.element.appendChild(btnPlay); config.element.appendChild(btnRecord); config.element.appendChild(btnStop); + config.element.appendChild(btnSave); __log('Interface built.'); return this;