From ed1ac48c0000f0cd4e729753f36d544def52d6a2 Mon Sep 17 00:00:00 2001 From: Rich-Harris Date: Tue, 18 Apr 2017 15:22:57 -0400 Subject: [PATCH] prevent audio restarting when it reaches the end --- src/generators/dom/visitors/Element/Binding.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/generators/dom/visitors/Element/Binding.js b/src/generators/dom/visitors/Element/Binding.js index 5b24d3f3a4..e88fe8df43 100644 --- a/src/generators/dom/visitors/Element/Binding.js +++ b/src/generators/dom/visitors/Element/Binding.js @@ -99,7 +99,12 @@ export default function visitBinding ( generator, block, state, node, attribute } else if ( attribute.name === 'paused' ) { - updateElement = `${state.parentNode}[ ${snippet} ? 'pause' : 'play' ]();`; + // this is necessary to prevent the audio restarting by itself + const last = block.getUniqueName( `${state.parentNode}_paused_value` ); + block.builders.create.addLine( `var ${last} = true;` ); + + updateCondition += ` && ${last} !== ( ${last} = ${snippet} )`; + updateElement = `${state.parentNode}[ ${last} ? 'pause' : 'play' ]();`; } }