add media state check

This commit is contained in:
Yanzhen Yu
2020-01-12 18:01:37 +08:00
parent 388ec6c30c
commit a7a3a76af1
4 changed files with 50 additions and 0 deletions

View File

@@ -152,6 +152,16 @@ function buildNode(
if (name === 'rr_height') {
(node as HTMLElement).style.height = value;
}
if (name === 'rr_mediaState') {
switch (value) {
case 'played':
(node as HTMLMediaElement).play();
case 'paused':
(node as HTMLMediaElement).pause();
break;
default:
}
}
}
}
return node;

View File

@@ -253,6 +253,12 @@ function serializeNode(
if (tagName === 'canvas') {
attributes.rr_dataURL = (n as HTMLCanvasElement).toDataURL();
}
// media elements
if (tagName === 'audio' || tagName === 'video') {
attributes.rr_mediaState = (n as HTMLMediaElement).paused
? 'paused'
: 'played';
}
if (needBlock) {
const { width, height } = (n as HTMLElement).getBoundingClientRect();
attributes.rr_width = `${width}px`;