summaryrefslogtreecommitdiffstats
path: root/dom/media/mediasource/test/test_AudioChange_mp4.html
blob: 95f48cadff92aae93c67fceebe33cdae4e6d417c (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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
<!DOCTYPE HTML>
<html>
<head>
  <title>MSE: basic functionality</title>
  <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
  <script type="text/javascript" src="mediasource.js"></script>
  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<pre id="test">
<script class="testbody" type="text/javascript">

SimpleTest.waitForExplicitFinish();

// This test checks loading a stereo segment, followed by a 5.1 segment plays without error.

runWithMSE(function(ms, el) {
  el.controls = true;
  once(ms, 'sourceopen').then(function() {
    // Log events for debugging.
    var events = ["suspend", "play", "canplay", "canplaythrough", "loadstart", "loadedmetadata",
                  "loadeddata", "playing", "ended", "error", "stalled", "emptied", "abort",
                  "waiting", "pause", "durationchange", "seeking", "seeked"];
    function logEvent(e) {
      var v = e.target;
      info("got " + e.type + " event");
    }
    events.forEach(function(e) {
      el.addEventListener(e, logEvent, false);
    });

    ok(true, "Receive a sourceopen event");
    var audiosb = ms.addSourceBuffer("audio/mp4");
    el.addEventListener("error", function(e) {
      ok(false, "should not fire '" + e.type + "' event");
      SimpleTest.finish();
    });
    is(el.readyState, el.HAVE_NOTHING, "readyState is HAVE_NOTHING");
    fetchAndLoad(audiosb, 'aac20-48000-64000-', ['init'], '.mp4')
    .then(once.bind(null, el, 'loadedmetadata'))
    .then(function() {
      ok(true, "got loadedmetadata event");
      var promises = [];
      promises.push(once(el, 'loadeddata'));
      promises.push(once(el, 'canplay'));
      promises.push(fetchAndLoad(audiosb, 'aac20-48000-64000-', ['1'], '.m4s'));
      return Promise.all(promises);
    })
    .then(function() {
      ok(true, "got canplay event");
      el.play();
      return fetchAndLoad(audiosb, 'aac51-48000-128000-', ['init'], '.mp4');
    })
    .then(fetchAndLoad.bind(null, audiosb, 'aac51-48000-128000-', ['2'], '.m4s'))
    .then(function() {
      var promises = [];
      ms.endOfStream();
      promises.push(once(el, 'ended'));
      promises.push(once(audiosb, 'updateend'));
      return Promise.all(promises);
    })
    .then(function() {
      ok(el.currentTime >= 6, "played to the end");
      SimpleTest.finish();
    })
  });
});

</script>
</pre>
</body>
</html>