index.html 2.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. <!doctype html>
  2. <html>
  3. <head>
  4. <meta charset="utf-8">
  5. <title>videojs-contrib-media-sources Demo</title>
  6. <link href="/node_modules/video.js/dist/video-js.css" rel="stylesheet">
  7. <style>
  8. p {
  9. background-color: #ddd;
  10. border: thin solid #333;
  11. padding: 8px;
  12. }
  13. </style>
  14. </head>
  15. <body>
  16. <p>The video below is generated by passing in the bytes of an FLV directly into video.js with
  17. <a href="https://dvcs.w3.org/hg/html-media/raw-file/tip/media-source/media-source.html">Media Source Extensions</a>.
  18. Load this page up through a web server to see it in action.
  19. </p>
  20. <video id='videojs-contrib-media-sources-player' class="video-js vjs-default-skin" controls></video>
  21. <ul>
  22. <li><a href="/test/">Run unit tests in browser.</a></li>
  23. <li><a href="/docs/api/">Read generated docs.</a></li>
  24. </ul>
  25. <script src="/node_modules/video.js/dist/video.js"></script>
  26. <script src="/dist/videojs-contrib-media-sources.js"></script>
  27. <script>
  28. (function(window, videojs) {
  29. var req = new XMLHttpRequest();
  30. var player = window.player = videojs('videojs-contrib-media-sources-player');
  31. // the flash-based media sources implementation only supports FLV video data
  32. // use XMLHttpRequest to get the raw byte array of an example FLV
  33. req.open('GET', 'barsandtone.flv', true);
  34. req.responseType = 'arraybuffer';
  35. req.onload = function(event) {
  36. // create a new media source to hold the data buffers
  37. var mediaSource = new videojs.MediaSource();
  38. // wrap the arraybuffer in a view so we can easily work with the
  39. // individual bytes
  40. var bytes = new Uint8Array(req.response);
  41. var url;
  42. // when a media source is assigned to a video element the `sourceopen`
  43. // event fires
  44. mediaSource.addEventListener('sourceopen', function(e) {
  45. // construct the video data buffer and set the appropriate MIME type
  46. var sourceBuffer = mediaSource.addSourceBuffer('video/flv; codecs="vp6,aac"');
  47. // start feeding bytes to the buffer
  48. // the video element that is reading from the associated media buffer is
  49. // ready to start playing now
  50. sourceBuffer.appendBuffer(bytes, video);
  51. }, false);
  52. // to assign a media source to a video element, you have to create a URL for it
  53. url = videojs.URL.createObjectURL(mediaSource);
  54. // assign the media source URL to video.js
  55. player.src({
  56. src: url,
  57. type: 'video/flv'
  58. });
  59. };
  60. req.send(null);
  61. }(window, window.videojs));
  62. </script>
  63. </body>
  64. </html>