summaryrefslogtreecommitdiffstats
path: root/dom/media/test/file_playback_and_bfcache.html
blob: 4798e1487eea5a1cea538eb7daa5c4b38f921191 (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
<!DOCTYPE HTML>
<html>
<head>
  <script>
  function init() {
    if (location.search == "") {
      let bc1 = new BroadcastChannel("bc1");
      bc1.onmessage = function(e) {
        if (e.data == "loadNext") {
          location.href = location.href + "?page2";
        } else if (e.data == "forward") {
          bc1.close();
          history.forward();
        }
      };
      window.onpageshow = function() {
        bc1.postMessage("pageshow");
      };
    } else {
      document.body.innerHTML = "<video controls src='owl.mp3' autoplay>";
      let bc2 = new BroadcastChannel("bc2");
      bc2.onmessage = function(e) {
        if (e.data == "back") {
          history.back();
        } else if (e.data == "statistics") {
          bc2.postMessage({ currentTime: document.body.firstChild.currentTime,
                          duration: document.body.firstChild.duration });
          bc2.close();
          window.close();
        }
      }
      window.onpageshow = function(e) {
        bc2.postMessage({ event: "pageshow", persisted: e.persisted});
        if (!e.persisted) {
          // The initial statistics is sent once we know the duration and
          // have loaded all the data.
          let mediaElement = document.body.firstChild;
          mediaElement.onpause = function() {
            mediaElement.onpause = null;
            mediaElement.currentTime = 0;
            mediaElement.onplay = function() {
              setTimeout(function() {
                bc2.postMessage({ currentTime: mediaElement.currentTime,
                                  duration: mediaElement.duration });
                }, 500);
            }
            mediaElement.play();
          }
        }
      };
    }
  }
  </script>
</head>
<body onload="init()">
</body>
</html>