summaryrefslogtreecommitdiffstats
path: root/mobile/android/geckoview/src/androidTest/assets/www/context_menu_blob_buffered.html
blob: 950e48129e546dd197d0620af4543af0dd9b35de (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8" content="width=device-width, height=device-height" />
    <title>Context Menu Test Blob Buffered</title>
  </head>
  <body>
    <video id="video" controls preload></video>
  </body>
  <script>
    window.addEventListener("DOMContentLoaded", function () {
      const video = document.getElementById("video");
      const mediaSource = new MediaSource();
      video.src = URL.createObjectURL(mediaSource);
      mediaSource.addEventListener("sourceopen", createBuffer);

      function createBuffer(event) {
        const mediaSource = event.target;
        const assetURL = "/assets/www/videos/gizmo.webm";
        const codec = 'video/webm; codecs="opus"';
        const sourceBuffer = mediaSource.addSourceBuffer(codec);

        function addBuffer(response) {
          sourceBuffer.addEventListener("updateend", function () {
            mediaSource.endOfStream();
          });
          sourceBuffer.appendBuffer(response);
        }

        fetchVideoData(assetURL, addBuffer);
      }

      function fetchVideoData(assetURL, videoArrayBuffer) {
        const request = new XMLHttpRequest();
        request.open("get", assetURL);
        request.responseType = "arraybuffer";
        request.onload = function () {
          videoArrayBuffer(request.response);
        };
        request.send();
      }
    });
  </script>
</html>