playwright/test/assets/player.html

57 lines
1.1 KiB
HTML

<script>
async function playToTheEnd() {
const video = document.querySelector('video');
const result = new Promise(r => video.onended = r);
video.play();
return await result;
}
async function playOneFrame() {
const video = document.querySelector('video');
const result = new Promise(r => video.onpause = r);
video.ontimeupdate = () => {
video.pause();
video.ontimeupdate = null;
};
video.play();
return await result;
}
async function playNFrames(n) {
for (let i = 0; i < n; i++)
await playOneFrame();
}
async function countFrames() {
const video = document.querySelector('video');
if (!video.duration)
return 0;
if (video.currentTime)
await playToTheEnd();
let count = 0;
while (true) {
++count;
await playOneFrame();
if (video.ended)
break;
}
return count;
}
async function seekLastFrame() {
const frameCount = await countFrames();
await playNFrames(frameCount);
return frameCount;
}
</script>
<body>
<video controls>
<source src="v.webm" type="video/webm">
Your browser does not support HTML video.
</video>
</body>