Last active
August 29, 2015 13:55
-
-
Save ryanve/8703402 to your computer and use it in GitHub Desktop.
Play only one track at a time. When one track plays, pause the rest.
This file contains 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
// gist.github.com/ryanve/8703402 | |
// Play only one track at a time. | |
(function(doc, tags) { | |
var listen = 'addEventListener', some = tags.some, pause = function(e) { | |
this !== e && !this.ended && !this.paused && !e.ended && !e.paused && e.pause(); | |
}; | |
some && listen in doc && tags.some(function(tag) { | |
var live = doc.getElementsByTagName(tag), solo = function() { | |
some.call(live, pause, this); | |
}; | |
some.call(live, function(e) { | |
e[listen]('playing', solo, false); | |
}); | |
}); | |
}(document, ['audio'])); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment