tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_DurationUpdated_mp4.html (1598B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 <head>
      4  <title>MSE: append data and check that mediasource duration got updated</title>
      5  <script src="/tests/SimpleTest/SimpleTest.js"></script>
      6  <script type="text/javascript" src="mediasource.js"></script>
      7  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8 </head>
      9 <body>
     10 <pre id="test">
     11 <script class="testbody" type="text/javascript">
     12 
     13 SimpleTest.waitForExplicitFinish();
     14 
     15 runWithMSE(async (ms, v) => {
     16  await once(ms, "sourceopen");
     17  const sb = ms.addSourceBuffer("video/mp4");
     18 
     19  let durationChangeCount = 0;
     20  v.addEventListener("durationchange", () => durationChangeCount++);
     21 
     22  const arrayBuffer = await fetchWithXHR("bipbop/bipbop2s.mp4");
     23  sb.appendBuffer(new Uint8Array(arrayBuffer, 0, 1395));
     24 
     25  // Adding the first init segment will fire a durationchange.
     26  await Promise.all([once(sb, "updateend"), once(v, "loadedmetadata")]);
     27  ok(true, "got loadedmetadata");
     28  // Set mediasource duration to 0, so future appendBuffer
     29  // will update the mediasource duration.
     30  // Changing the duration will fire a durationchange.
     31  ms.duration = 0;
     32  sb.appendBuffer(new Uint8Array(arrayBuffer, 1395));
     33  // Adding more data will fire durationchange.
     34  await once(sb, "updateend");
     35  ok(true, "got updateend");
     36  // this will not fire durationchange as new duration == old duration
     37  ms.endOfStream();
     38  await once(ms, "sourceended");
     39  is(durationChangeCount, 3, "durationchange not fired as many times as expected");
     40  is(v.duration, 1.696666, "Video has correct duration");
     41  SimpleTest.finish();
     42 });
     43 
     44 </script>
     45 </pre>
     46 </body>
     47 </html>