Last active
December 30, 2015 12:39
-
-
Save kaecy/7830730 to your computer and use it in GitHub Desktop.
code demonstrating play on end. i.e, play next track on the ending of the first.
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 nil = 1; | |
| function getFirst(eName) { | |
| var firstElm = document.getElementsByTagName(eName)[0]; | |
| if (firstElm == undefined) | |
| return nil; | |
| return firstElm; | |
| } | |
| function Answer(bValue) { | |
| if ( | |
| bValue == true | |
| || bValue == 1 | |
| || bValue == "yes" | |
| ) | |
| this.isTrue = true; | |
| else this.isTrue = false; | |
| } | |
| DataMediator = new Object(); | |
| DataMediator.audio = []; | |
| function endListener() { | |
| var audioTag = getFirst("audio"); | |
| var audio = DataMediator.audio.shift(); | |
| if (new Answer(confirm("Play next track?\n" + audio)).isTrue ) { | |
| audioTag.src = audio; | |
| audioTag.load(); | |
| audioTag.play(); | |
| } | |
| if (DataMediator.audio.length == 0) | |
| audioTag.removeEventListener("ended", endListener, false); | |
| } | |
| function playOnEnd(fileParam) { | |
| var audioTag = getFirst("audio"); | |
| DataMediator.audio.push(fileParam); | |
| audioTag.addEventListener("ended", endListener, false); | |
| } |
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
| // prompts before it plays | |
| playOnEnd("two steps from hell/protectors of earth.mp3"); | |
| playOnEnd("two steps from hell/heart of courage.mp3"); |
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
| <!-- demo --> | |
| <html><body> | |
| <script src="play.js"></script> | |
| <audio src="example.ogg" autoplay></audio> | |
| <script src="x.js"></script> | |
| </body> | |
| </html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment