참고소스 수정본
This commit is contained in:
60
참고/playwright-main/tests/assets/player.html
Normal file
60
참고/playwright-main/tests/assets/player.html
Normal file
@@ -0,0 +1,60 @@
|
||||
<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();
|
||||
}
|
||||
|
||||
let _frameCount = -1;
|
||||
async function countFrames() {
|
||||
if (_frameCount === -1) {
|
||||
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;
|
||||
}
|
||||
_frameCount = count;
|
||||
}
|
||||
return _frameCount;
|
||||
}
|
||||
|
||||
async function seekLastFrame() {
|
||||
let 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>
|
||||
Reference in New Issue
Block a user