This repository has been archived by the owner on Jan 29, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 111
/
index.html
71 lines (64 loc) · 2.58 KB
/
index.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
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>videojs-contrib-media-sources Demo</title>
<link href="/node_modules/video.js/dist/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='videojs-contrib-media-sources-player' class="video-js vjs-default-skin" controls></video>
<ul>
<li><a href="/test/">Run unit tests in browser.</a></li>
<li><a href="/docs/api/">Read generated docs.</a></li>
</ul>
<script src="/node_modules/video.js/dist/video.js"></script>
<script src="/dist/videojs-contrib-media-sources.js"></script>
<script>
(function(window, videojs) {
var req = new XMLHttpRequest();
var player = window.player = videojs('videojs-contrib-media-sources-player');
// the flash-based media sources implementation only supports FLV video data
// use XMLHttpRequest to get the raw byte array of an example FLV
req.open('GET', 'barsandtone.flv', true);
req.responseType = 'arraybuffer';
req.onload = function(event) {
// create a new media source to hold the data buffers
var mediaSource = new videojs.MediaSource();
// wrap the arraybuffer in a view so we can easily work with the
// individual bytes
var bytes = new Uint8Array(req.response);
var url;
// when a media source is assigned to a video element the `sourceopen`
// event fires
mediaSource.addEventListener('sourceopen', function(e) {
// 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
player.src({
src: url,
type: 'video/flv'
});
};
req.send(null);
}(window, window.videojs));
</script>
</body>
</html>