Skip to content

Commit

Permalink
Make buffered/played/seekable attributes of media element bindable
Browse files Browse the repository at this point in the history
  • Loading branch information
martinandert committed Sep 5, 2017
1 parent 66c382a commit db0b6d7
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 3 deletions.
27 changes: 26 additions & 1 deletion src/generators/dom/visitors/Element/Binding.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,28 @@ export default function visitBinding(

updateConditions = [`${last} !== (${last} = ${snippet})`];
updateElement = `${state.parentNode}[${last} ? "pause" : "play"]();`;
} else if (attribute.name === 'buffered') {
const frame = block.getUniqueName(`${state.parentNode}_animationframe`);
block.addVariable(frame);
setter = deindent`
cancelAnimationFrame(${frame});
${frame} = requestAnimationFrame(${handler});
${setter}
`;

updateConditions.push(`${snippet}.start`);
readOnly = true;
} else if (attribute.name === 'seekable' || attribute.name === 'played') {
const frame = block.getUniqueName(`${state.parentNode}_animationframe`);
block.addVariable(frame);
setter = deindent`
cancelAnimationFrame(${frame});
if (!${state.parentNode}.paused) ${frame} = requestAnimationFrame(${handler});
${setter}
`;

updateConditions.push(`${snippet}.start`);
readOnly = true;
}
}

Expand Down Expand Up @@ -213,6 +235,9 @@ function getBindingEventName(node: Node, attribute: Node) {
if (attribute.name === 'currentTime') return 'timeupdate';
if (attribute.name === 'duration') return 'durationchange';
if (attribute.name === 'paused') return 'pause';
if (attribute.name === 'buffered') return 'progress';
if (attribute.name === 'seekable') return 'timeupdate';
if (attribute.name === 'played') return 'timeupdate';

return 'change';
}
Expand Down Expand Up @@ -317,4 +342,4 @@ function isComputed(node: Node) {
}

return false;
}
}
7 changes: 5 additions & 2 deletions src/validate/html/validateElement.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,10 @@ export default function validateElement(validator: Validator, node: Node, refs:
} else if (
name === 'currentTime' ||
name === 'duration' ||
name === 'paused'
name === 'paused' ||
name === 'buffered' ||
name === 'seekable' ||
name === 'played'
) {
if (node.name !== 'audio' && node.name !== 'video') {
validator.error(
Expand Down Expand Up @@ -202,4 +205,4 @@ function checkTypeAttribute(validator: Validator, node: Node) {

function isDynamic(attribute: Node) {
return attribute.value.length > 1 || attribute.value[0].type !== 'Text';
}
}

0 comments on commit db0b6d7

Please sign in to comment.