Skip to content

Commit

Permalink
insert audio element on page load
Browse files Browse the repository at this point in the history
  • Loading branch information
toolness committed Jul 10, 2012
1 parent a817959 commit d552250
Showing 1 changed file with 20 additions and 14 deletions.
34 changes: 20 additions & 14 deletions static/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -122,10 +122,28 @@
el.trigger("state-change");
}

function insertAudioElement() {
var playback = $(".playback", el);
var cacheBuster = "?bust=" + Date.now();
playback.empty();
var audio = document.createElement("audio");
audio.setAttribute("controls", "controls");
var source = document.createElement("source");
source.setAttribute("src", "recording.mp3" + cacheBuster);
source.setAttribute("type", "audio/mp3");
audio.appendChild(source);
source = document.createElement("source");
source.setAttribute("src", "recording.ogg" + cacheBuster);
source.setAttribute("type", "audio/ogg");
audio.appendChild(source);
playback.append(audio);
}

setRecordState("loading");
wami.setup({
id : $(".wami", el).attr("id"),
onReady : function() {
insertAudioElement();
setRecordState("idle");
}
});
Expand All @@ -144,33 +162,21 @@
});

$(".start", el).click(function startRecording() {
var playback = $(".playback", el);
if (recordState != "idle")
return;
setRecordState("pre-recording");
playback.empty();
$(".playback", el).empty();
wami.startRecording(baseURL + "/audio",
wami.nameCallback(function() {
setRecordState("recording");
}),
wami.nameCallback(function() {
playback.empty();
var audio = document.createElement("audio");
audio.setAttribute("controls", "controls");
var source = document.createElement("source");
source.setAttribute("src", "recording.mp3?bust=" + recordStart);
source.setAttribute("type", "audio/mp3");
audio.appendChild(source);
source = document.createElement("source");
source.setAttribute("src", "recording.ogg?bust=" + recordStart);
source.setAttribute("type", "audio/ogg");
audio.appendChild(source);
jQuery.ajax({
type: 'POST',
url: baseURL + '/metadata',
data: JSON.stringify(self.metadata),
success: function() {
playback.append(audio);
insertAudioElement();
},
error: function() {
el.trigger("error", "failed to upload metadata");
Expand Down

0 comments on commit d552250

Please sign in to comment.