Skip to content

Instantly share code, notes, and snippets.

@benvium
Created September 19, 2012 12:15
Show Gist options
  • Select an option

  • Save benvium/3749337 to your computer and use it in GitHub Desktop.

Select an option

Save benvium/3749337 to your computer and use it in GitHub Desktop.
Example HTML5 Audio usage. Notes of what doesn't work if you *DON'T* have a streaming server.
var url = "path/to/my/audio.mp3";
var ap = new window.Audio();
var isLoaded = false;
ap.addEventListener('canplay', function () {
isLoaded = true;
console.log(url.split("/").pop() + " loaded");
this.play();
}, false);
ap.addEventListener('error', function () {
isLoaded = false;
console.log(url.split("/").pop() + " failed to load");
}, false);
ap.src = "content/" + url; // convert from 'raw' to 'actual'
ap.load();
ap.loop = true; // XXXX Audio didn't loop!
ap.addEventListener('ended', function () {
// XXXX attempt to manually loop. Doesn't work!
this.currentTime = 0;
this.play();
}, false );
function seekTo(time) {
// XXXX doesn't work!
ap.currentTime = time;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment