]> git.parisson.com Git - mezzo.git/commitdiff
Pause all audio if we play one
authorJérémy Fabre <Jeremy@iMac-de-Jeremy.local>
Thu, 22 Sep 2016 14:37:26 +0000 (16:37 +0200)
committerJérémy Fabre <Jeremy@iMac-de-Jeremy.local>
Thu, 22 Sep 2016 14:37:26 +0000 (16:37 +0200)
app/static/src/js/modules/audio.js

index 6e807085ba47f26d3e0619b81d2cc15575119bef..8b8ab8fbc71050d7f83cf6af5e9273ad93e139c9 100644 (file)
@@ -26,6 +26,10 @@ Audio.prototype.init = function() {
             as[i].title = $('<div class="title"></div>');
             $(as[i].wrapper).append(as[i].title);
 
+            as[i].element.onplay = function (e) {
+                that.pauseAllExcept(this);
+            };
+
             //
             // Future refs
             //
@@ -76,6 +80,21 @@ Audio.prototype.init = function() {
 
 };
 
+Audio.prototype.pauseAllExcept = function(audio) {
+
+    var that = this,
+        i = 0;
+
+    for(i=0; i<that.audios.length; i++) {
+
+        if(that.audios[i].element != audio) {
+            that.audios[i].element.pause();
+        }
+
+    }
+
+};
+
 Audio.prototype.setTitle = function(audio, title) {
 
     var split = title.split(",");