Skip to content

Commit

Permalink
Add audio/video volume binding
Browse files Browse the repository at this point in the history
  • Loading branch information
jacobmischka committed Feb 3, 2018
1 parent 56e9343 commit 24e5d3c
Show file tree
Hide file tree
Showing 6 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/generators/nodes/Attribute.ts
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,7 @@ const attributeLookup = {
'textarea',
],
},
volume: { appliesTo: ['audio', 'video'] },
width: {
appliesTo: ['canvas', 'embed', 'iframe', 'img', 'input', 'object', 'video'],
},
Expand Down
4 changes: 2 additions & 2 deletions src/generators/nodes/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ export default class Binding extends Node {
);
}

if (this.name === 'currentTime') {
if (this.name === 'currentTime' || this.name === 'volume') {
updateCondition = `!isNaN(${snippet})`;
initialUpdate = null;
}
Expand Down Expand Up @@ -267,4 +267,4 @@ function isComputed(node: Node) {
}

return false;
}
}
3 changes: 2 additions & 1 deletion src/validate/html/validateElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,8 @@ export default function validateElement(
name === 'paused' ||
name === 'buffered' ||
name === 'seekable' ||
name === 'played'
name === 'played' ||
name === 'volume'
) {
if (node.name !== 'audio' && node.name !== 'video') {
validator.error(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,25 @@ export default {
test ( assert, component, target, window ) {
assert.equal( component.get( 't' ), 0 );
assert.equal( component.get( 'd' ), 0 );
assert.equal( component.get( 'v' ), 0.5 );
assert.equal( component.get( 'paused' ), true );

const audio = target.querySelector( 'audio' );
const timeupdate = new window.Event( 'timeupdate' );
const durationchange = new window.Event( 'durationchange' );
const volumechange = new window.Event( 'volumechange' );

audio.currentTime = 10;
audio.duration = 20;
audio.volume = 0.75;
audio.dispatchEvent( timeupdate );
audio.dispatchEvent( durationchange );
audio.dispatchEvent( volumechange );
audio.play();

assert.equal( component.get( 't' ), 10 );
assert.equal( component.get( 'd' ), 0 ); // not 20, because read-only. Not sure how to test this!
assert.equal( component.get( 'v' ), 0.75 );
assert.equal( component.get( 'paused' ), true ); // ditto...
component.destroy();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
<audio bind:currentTime='t' bind:duration='d' bind:paused bind:volume='v'
src='music.mp3'></audio>

This file was deleted.

0 comments on commit 24e5d3c

Please sign in to comment.