bb24ae98 by Simeon Bateman Committed by David LaPalomento

setup test to pull in header and segment of mp4 file and push to media source extension

1 parent 7a821603
1 <!DOCTYPE html>
2 <!--[if lt IE 7]> <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
3 <!--[if IE 7]> <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
4 <!--[if IE 8]> <html class="no-js lt-ie9"> <![endif]-->
5 <!--[if gt IE 8]><!--> <html class="no-js"> <!--<![endif]-->
6 <head>
7 <meta charset="utf-8">
8 <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
9 <title></title>
10 <meta name="description" content="">
11 <meta name="viewport" content="width=device-width">
12
13 <link rel="stylesheet" href="css/normalize.min.css">
14 <link rel="stylesheet" href="css/main.css">
15
16 <script src="js/vendor/modernizr-2.6.2.min.js"></script>
17 </head>
18 <body>
19 <!--[if lt IE 7]>
20 <p class="chromeframe">You are using an <strong>outdated</strong> browser. Please <a href="http://browsehappy.com/">upgrade your browser</a> or <a href="http://www.google.com/chromeframe/?redirect=true">activate Google Chrome Frame</a> to improve your experience.</p>
21 <![endif]-->
22
23 <div class="header-container">
24 <header class="wrapper clearfix">
25 <h1 class="title">Transmux Analyzer</h1>
26 </header>
27 </div>
28
29 <div class="main-container">
30 <div class="main wrapper clearfix">
31
32 <article>
33 <header>
34 <p>
35 This page will show a video player that loads a header of an mp4 followed by an mp4 segment.
36 </p>
37 </header>
38 <section>
39 <video controls autoplay width="320" height="240"></video>
40 </section>
41 </article>
42
43 </div> <!-- #main -->
44 </div> <!-- #main-container -->
45
46 <div class="footer-container">
47 <footer class="wrapper">
48 <h3></h3>
49 </footer>
50 </div>
51
52
53
54
55
56 <script>
57 var ms,
58 sourceBuffer,
59 video;
60
61
62 function closed() {
63 window.alert("MediaSource Closed.");
64 }
65
66 function append(buffer, bytes) {
67 if ("append" in buffer) {
68 buffer.append(bytes);
69 } else if ("appendBuffer" in buffer) {
70 buffer.appendBuffer(bytes);
71 }
72 }
73
74 function loadFragment() {
75 console.log("LOAD FRAGMENT");
76 var req = new XMLHttpRequest();
77 req.responseType = "arraybuffer";
78 req.open("GET", "./0.m4s", true);
79
80
81 req.onload = function () {
82 console.log("FRAGMENT DONE LOADING");
83
84 append(sourceBuffer, new Uint8Array(req.response));
85 video.play();
86 };
87
88 req.onerror = function () {
89 window.alert("Could not load fragment.");
90 };
91
92 req.send();
93
94 }
95
96 function loadInit() {
97
98 console.log("LOAD INIT");
99 var req = new XMLHttpRequest();
100 req.responseType = "arraybuffer";
101 req.open("GET", "./Header.m4s", true);
102
103 req.onload = function () {
104 console.log("INIT DONE LOADING");
105 append(sourceBuffer, new Uint8Array(req.response));
106 loadFragment();
107 };
108
109 req.onerror = function () {
110 window.alert("Could not load init.");
111 };
112
113 req.send();
114
115 }
116
117 function opened() {
118
119 console.log("OPENED");
120 sourceBuffer = ms.addSourceBuffer('video/mp4;codecs="avc1.4D400D"');
121
122 loadInit();
123 }
124
125 function load() {
126 console.log("START");
127 window.MediaSource = window.MediaSource || window.WebKitMediaSource;
128
129 ms = new MediaSource();
130
131 video = document.querySelector('video');
132 video.src = window.URL.createObjectURL(ms);
133
134 ms.addEventListener('webkitsourceopen', opened, false);
135 ms.addEventListener('webkitsourceclose', closed, false);
136
137 ms.addEventListener('sourceopen', opened, false);
138 ms.addEventListener('sourceclose', closed, false);
139 }
140 load();
141 </script>
142 </body>
143 </html>