You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
72 lines
2.6 KiB
72 lines
2.6 KiB
<!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>
|