Skip to content

Instantly share code, notes, and snippets.

@ryanve
Last active August 29, 2015 13:55
Show Gist options
  • Save ryanve/8703402 to your computer and use it in GitHub Desktop.
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.
// 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