Skip to content

Truly independent web browser

1.5 KB
Raw Blame
<!DOCTYPE html>
<script>internals.setAutoplayPolicy("allow-audio-and-video");</script>
<script src="../include.js"></script>
<script src="media-source-presented-frame-include.js"></script>
<script>
    // Pauses long enough for frames after the playhead to be decoded ahead, then replaces those frames. Playback must
    // present the new frames rather than the ones that were decoded before the replacement.
    promiseTest(async () => {
        const red = await fetchColoredStream("red");
        const blue = await fetchColoredStream("blue");

        const video = document.createElement("video");
        video.muted = true;
        document.body.append(video);
        const { sourceBuffer } = await openColoredStreamSource(video);

        await appendWithinWindow(sourceBuffer, red);
        await seekAndWait(video, 0.55);
        println(`before replacing: ${await samplePresentedFrameOnceItMatches(video, "red 0")}`);
        await timeout(500);

        // Frames are at multiples of 0.1, so this keeps the presented frame at 0.5 and the next at 0.6. Reads that skip
        // the replacement go on to the red frames from 11.
        await appendWithinWindow(sourceBuffer, blue, 0.65, 11);
        println(`after replacing ahead: ${samplePresentedFrame(video)}`);

        const firstReplacedFrameColor = presentedColorOfFirstFrameFrom(video, 0.65);
        await video.play();
        println(`first frame presented past 0.65: ${await firstReplacedFrameColor}`);
        video.pause();
    });
</script>