From ca4d37c85c62494697ce893e6333d7d7f3e9cc0e Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Wed, 2 Jan 2019 11:40:27 +0100 Subject: [PATCH 1/3] HFP-1145 Stop audio when turning another card --- card.js | 35 +++++++++++++++++++---------------- memory-game.js | 11 ++++++++++- 2 files changed, 29 insertions(+), 17 deletions(-) diff --git a/card.js b/card.js index 9919018..81e9219 100644 --- a/card.js +++ b/card.js @@ -66,11 +66,13 @@ var handlePlaying = function () { if ($card) { $card.addClass('h5p-memory-audio-playing'); + self.trigger('audioplay'); } }; var handleStopping = function () { if ($card) { $card.removeClass('h5p-memory-audio-playing'); + self.trigger('audiostop'); } }; audioPlayer.addEventListener('play', handlePlaying); @@ -115,24 +117,20 @@ return; } - if (audioPlayer) { - audioPlayer.play(); - } - $card.addClass('h5p-flipped'); self.trigger('flip'); flippedState = true; + + if (audioPlayer) { + audioPlayer.play(); + } }; /** * Flip card back. */ self.flipBack = function () { - if (audioPlayer) { - audioPlayer.pause(); - audioPlayer.currentTime = 0; - } - + self.stopAudio(); self.updateLabel(null, null, true); // Reset card label $card.removeClass('h5p-flipped'); flippedState = false; @@ -150,11 +148,7 @@ * Reset card to natural state */ self.reset = function () { - if (audioPlayer) { - audioPlayer.pause(); - audioPlayer.currentTime = 0; - } - + self.stopAudio(); self.updateLabel(null, null, true); // Reset card label flippedState = false; removedState = false; @@ -236,8 +230,7 @@ $card.children('.h5p-back') .click(function () { if ($card.hasClass('h5p-memory-audio-playing')) { - audioPlayer.pause(); - audioPlayer.currentTime = 0; + self.stopAudio(); } else { audioPlayer.play(); @@ -289,6 +282,16 @@ self.isRemoved = function () { return removedState; }; + + /** + * Stop any audio track that might be playing. + */ + self.stopAudio = function () { + if (audioPlayer) { + audioPlayer.pause(); + audioPlayer.currentTime = 0; + } + }; }; // Extends the event dispatcher diff --git a/memory-game.js b/memory-game.js index 07bbd0d..bf19a3e 100644 --- a/memory-game.js +++ b/memory-game.js @@ -22,7 +22,7 @@ H5P.MemoryGame = (function (EventDispatcher, $) { // Initialize event inheritance EventDispatcher.call(self); - var flipped, timer, counter, popup, $bottom, $taskComplete, $feedback, $wrapper, maxWidth, numCols; + var flipped, timer, counter, popup, $bottom, $taskComplete, $feedback, $wrapper, maxWidth, numCols, audioCard; var cards = []; var flipBacks = []; // Que of cards to be flipped back var numFlipped = 0; @@ -218,6 +218,9 @@ H5P.MemoryGame = (function (EventDispatcher, $) { */ var addCard = function (card, mate) { card.on('flip', function () { + if (audioCard) { + audioCard.stopAudio(); + } // Always return focus to the card last flipped for (var i = 0; i < cards.length; i++) { @@ -260,6 +263,12 @@ H5P.MemoryGame = (function (EventDispatcher, $) { // Count number of cards turned counter.increment(); }); + card.on('audioplay', function () { + audioCard = card; + }); + card.on('audiostop', function () { + audioCard = undefined; + }); /** * Create event handler for moving focus to the next or the previous From e5ce754c92240581c5415ea4b09c194ecfa4eb07 Mon Sep 17 00:00:00 2001 From: Frode Petterson Date: Wed, 2 Jan 2019 11:47:35 +0100 Subject: [PATCH 2/3] HFP-1145 Fix always stop playing on play --- memory-game.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/memory-game.js b/memory-game.js index bf19a3e..4b63def 100644 --- a/memory-game.js +++ b/memory-game.js @@ -264,6 +264,9 @@ H5P.MemoryGame = (function (EventDispatcher, $) { counter.increment(); }); card.on('audioplay', function () { + if (audioCard) { + audioCard.stopAudio(); + } audioCard = card; }); card.on('audiostop', function () { From 2f44a88c45bc21b0e36f71de73e3ab6683fedb6c Mon Sep 17 00:00:00 2001 From: Paal Joergensen Date: Fri, 4 Jan 2019 14:58:46 +0100 Subject: [PATCH 3/3] Update language/pt-br.json --- language/pt-br.json | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/language/pt-br.json b/language/pt-br.json index 8133dc7..c7086ed 100644 --- a/language/pt-br.json +++ b/language/pt-br.json @@ -18,6 +18,10 @@ "label": "Texto alternativo para a imagem", "description": "Descreva o que pode ser visto na foto. O texto será lido para os usuários que necessitam utilizar leitores de tela." }, + { + "label": "Audio Track", + "description": "An optional sound that plays when the card is turned." + }, { "label": "Imagem-par", "description": "Uma imagem opcional para ser combinada ao invés de utilizar dois cartões com a mesma imagem." @@ -26,6 +30,10 @@ "label": "Texto alternativo para a Imagem-par", "description": "Descreva o que pode ser visto na foto. O texto será lido para os usuários que necessitam utilizar leitores de tela." }, + { + "label": "Matching Audio Track", + "description": "An optional sound that plays when the second card is turned." + }, { "label": "Descrição", "description": "Um texto curto opcional que aparecerá quando duas cartas forem combinadas corretamente."