forked from videojs/videojs-contrib-media-sources
-
Notifications
You must be signed in to change notification settings - Fork 0
/
example.html
73 lines (58 loc) · 2.19 KB
/
example.html
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
73
<!doctype html>
<html>
<head>
<title>Media Sources Example</title>
<link href="node_modules/video.js/dist/video-js/video-js.css" rel="stylesheet">
<style>
p {
background-color: #ddd;
border: thin solid #333;
padding: 8px;
}
</style>
</head>
<body>
<p>The video below is generated by passing in the bytes of an FLV directly into video.js with <a href="https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html">Media Source Extensions</a>. Load this page up through a web server to see it in action.</p>
<video id='video' class="video-js vjs-default-skin" height="300" width="600" controls></video>
<script src="node_modules/video.js/dist/video-js/video.js"></script>
<script src="videojs-media-sources.js"></script>
<script>
var
video,
req = new XMLHttpRequest();
// initialize video.js
video = videojs('video');
// the flash-based media sources implementation only supports FLV video data
// use XMLHttpRequest2 to get the raw byte array of an example FLV
req.open('GET', 'barsandtone.flv', true);
req.responseType = 'arraybuffer';
req.onload = function(event){
var
// create a new media source to hold the data buffers
mediaSource = new videojs.MediaSource(),
// wrap the arraybuffer in a view so we can easily work with the
// individual bytes
bytes = new Uint8Array(req.response),
url;
// when a media source is assigned to a video element the `sourceopen`
// event fires
mediaSource.addEventListener('sourceopen', function(event){
// construct the video data buffer and set the appropriate MIME type
var sourceBuffer = mediaSource.addSourceBuffer('video/flv; codecs="vp6,aac"');
// start feeding bytes to the buffer
// the video element that is reading from the associated media buffer is
// ready to start playing now
sourceBuffer.appendBuffer(bytes, video);
}, false);
// to assign a media source to a video element, you have to create a URL for it
url = videojs.URL.createObjectURL(mediaSource);
// assign the media source URL to video.js
video.src({
src: url,
type: "video/flv"
});
};
req.send(null);
</script>
</body>
</html>