From 190d2c64209932d3f6f96113d4c0bedd6639684d Mon Sep 17 00:00:00 2001 From: Antoine Date: Sun, 10 Apr 2016 14:17:50 +0200 Subject: [PATCH] Stoppe la lecture en cours --- js/app/models/sound.js | 4 +++- js/app/views/sounds.js | 11 +++++++++-- 2 files changed, 12 insertions(+), 3 deletions(-) diff --git a/js/app/models/sound.js b/js/app/models/sound.js index 62751b7..9390c09 100644 --- a/js/app/models/sound.js +++ b/js/app/models/sound.js @@ -15,7 +15,9 @@ define( play: function() { var audio = new Audio('sounds/'+this.attributes.file); - return audio.play(); + audio.play(); + + return audio; } }); diff --git a/js/app/views/sounds.js b/js/app/views/sounds.js index f7015c3..69943d0 100644 --- a/js/app/views/sounds.js +++ b/js/app/views/sounds.js @@ -11,7 +11,7 @@ define( "use strict"; var SoundListView = Marionette.LayoutView.extend({ - collection : new SoundsCollection(), + collection: new SoundsCollection(), template: SoundListTemplate, ui: { soundItem: 'li a' @@ -39,8 +39,15 @@ define( e.preventDefault(); + this.stopCurrentPlay(); + if( sound ) { - sound.play(); + this.currentPlay = sound.play(); + } + }, + stopCurrentPlay: function() { + if( this.currentPlay && !this.currentPlay.paused ) { + this.currentPlay.pause(); } }, serializeData: function () {