Created
September 19, 2012 12:15
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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