tor-browser

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

test_mp3_broadcast.html (2235B)


      1 <!DOCTYPE HTML>
      2 <html>
      3 
      4 <head>
      5    <title>Test playback of broadcast-like streams</title>
      6    <script src="/tests/SimpleTest/SimpleTest.js"></script>
      7    <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
      8    <script type="text/javascript" src="manifest.js"></script>
      9 </head>
     10 
     11 <body>
     12    <audio controls id=a style="width: 100%;"></audio>
     13    <script type="module">
     14        SimpleTest.waitForExplicitFinish();
     15        const streams = [
     16            // An mp3 bytestream consisting of a complete mp3 file with a XING
     17            // header, that has duration information, but served without a
     18            // `Content-Length`. It is followed by a second mp3 bytestream that
     19            // also has a XING header. While some software are able to play the
     20            // entire file, Web browser don't.
     21            { src: "two-xing-header-no-content-length.mp3", duration: 1 },
     22            // An mp3 bytestream consisting of a complete mp3 file with a XING
     23            // header, that has duration information, but served without a
     24            // `Content-Length` header. It is followed by a second mp3 bytestream that
     25            // doesn't have a XING header.
     26            // This scenario is typical in radio broadcast scenario, when the
     27            // live-stream has a pre-recorded prelude. The reported duration,
     28            // after "ended" has been received, is the duration of playback.
     29            { src: "single-xing-header-no-content-length.mp3", duration: 11.050839},
     30        ];
     31        var audio = window.a;
     32        // Prevent ESLint error about top-level await
     33        (async function () {
     34            for (let i of streams) {
     35                audio.src = i.src;
     36                audio.load();
     37                audio.play();
     38                audio.onerror = (e) => {
     39                    ok(false, `${i}: error: ${e.message}}`);
     40                };
     41                await once(audio, "ended");
     42                ok(true, `${i}: playback through the end`);
     43                is(audio.duration, i.duration, "Duration at end is correct");
     44                is(audio.currentTime, i.duration, "Current time at end is correct");
     45            }
     46            SimpleTest.finish();
     47        })()
     48    </script>
     49 </body>
     50 
     51 </html>