Skip to content

Commit

Permalink
Move callback processing to new "save" button.
Browse files Browse the repository at this point in the history
  • Loading branch information
pauln committed Dec 3, 2014
1 parent 4cc70e8 commit d8d24b9
Showing 1 changed file with 16 additions and 6 deletions.
22 changes: 16 additions & 6 deletions js/recordmp3.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -92,6 +93,7 @@
}
btnStop.disabled = true;
btnRecord.disabled = false;
btnSave.disabled = false;
}

this.stopRecording = function(){
Expand Down Expand Up @@ -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' });
}
Expand All @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit d8d24b9

Please sign in to comment.