Skip to content

Commit db0b6d7

Browse files
committed
Make buffered/played/seekable attributes of media element bindable
1 parent 66c382a commit db0b6d7

File tree

2 files changed

+31
-3
lines changed

2 files changed

+31
-3
lines changed

src/generators/dom/visitors/Element/Binding.ts

+26-1
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,28 @@ export default function visitBinding(
138138

139139
updateConditions = [`${last} !== (${last} = ${snippet})`];
140140
updateElement = `${state.parentNode}[${last} ? "pause" : "play"]();`;
141+
} else if (attribute.name === 'buffered') {
142+
const frame = block.getUniqueName(`${state.parentNode}_animationframe`);
143+
block.addVariable(frame);
144+
setter = deindent`
145+
cancelAnimationFrame(${frame});
146+
${frame} = requestAnimationFrame(${handler});
147+
${setter}
148+
`;
149+
150+
updateConditions.push(`${snippet}.start`);
151+
readOnly = true;
152+
} else if (attribute.name === 'seekable' || attribute.name === 'played') {
153+
const frame = block.getUniqueName(`${state.parentNode}_animationframe`);
154+
block.addVariable(frame);
155+
setter = deindent`
156+
cancelAnimationFrame(${frame});
157+
if (!${state.parentNode}.paused) ${frame} = requestAnimationFrame(${handler});
158+
${setter}
159+
`;
160+
161+
updateConditions.push(`${snippet}.start`);
162+
readOnly = true;
141163
}
142164
}
143165

@@ -213,6 +235,9 @@ function getBindingEventName(node: Node, attribute: Node) {
213235
if (attribute.name === 'currentTime') return 'timeupdate';
214236
if (attribute.name === 'duration') return 'durationchange';
215237
if (attribute.name === 'paused') return 'pause';
238+
if (attribute.name === 'buffered') return 'progress';
239+
if (attribute.name === 'seekable') return 'timeupdate';
240+
if (attribute.name === 'played') return 'timeupdate';
216241

217242
return 'change';
218243
}
@@ -317,4 +342,4 @@ function isComputed(node: Node) {
317342
}
318343

319344
return false;
320-
}
345+
}

src/validate/html/validateElement.ts

+5-2
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,10 @@ export default function validateElement(validator: Validator, node: Node, refs:
9999
} else if (
100100
name === 'currentTime' ||
101101
name === 'duration' ||
102-
name === 'paused'
102+
name === 'paused' ||
103+
name === 'buffered' ||
104+
name === 'seekable' ||
105+
name === 'played'
103106
) {
104107
if (node.name !== 'audio' && node.name !== 'video') {
105108
validator.error(
@@ -202,4 +205,4 @@ function checkTypeAttribute(validator: Validator, node: Node) {
202205

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

0 commit comments

Comments
 (0)