1 | # video.js HLS Source Handler
|
2 |
|
3 | [![Build Status][travis-icon]][travis-link]
|
4 | [![Slack Status][slack-icon]][slack-link]
|
5 |
|
6 |
|
7 | Play back HLS with video.js, even where it's not natively supported.
|
8 |
|
9 | Lead Maintainer: Jon-Carlos Rivera [@imbcmdth](https://github.com/imbcmdth)
|
10 |
|
11 | Maintenance Status: Stable
|
12 |
|
13 |
|
14 |
|
15 | **Table of Contents** *generated with [DocToc](https://github.com/thlorenz/doctoc)*
|
16 |
|
17 | - [Installation](#installation)
|
18 | - [NPM](#npm)
|
19 | - [CDN](#cdn)
|
20 | - [Releases](#releases)
|
21 | - [Manual Build](#manual-build)
|
22 | - [Contributing](#contributing)
|
23 | - [Talk to us](#talk-to-us)
|
24 | - [Getting Started](#getting-started)
|
25 | - [Video.js 6](#videojs-6)
|
26 | - [Documentation](#documentation)
|
27 | - [Options](#options)
|
28 | - [How to use](#how-to-use)
|
29 | - [Initialization](#initialization)
|
30 | - [Source](#source)
|
31 | - [List](#list)
|
32 | - [withCredentials](#withcredentials)
|
33 | - [useCueTags](#usecuetags)
|
34 | - [overrideNative](#overridenative)
|
35 | - [blacklistDuration](#blacklistduration)
|
36 | - [bandwidth](#bandwidth)
|
37 | - [Runtime Properties](#runtime-properties)
|
38 | - [hls.playlists.master](#hlsplaylistsmaster)
|
39 | - [hls.playlists.media](#hlsplaylistsmedia)
|
40 | - [hls.segmentXhrTime](#hlssegmentxhrtime)
|
41 | - [hls.bandwidth](#hlsbandwidth)
|
42 | - [hls.bytesReceived](#hlsbytesreceived)
|
43 | - [hls.selectPlaylist](#hlsselectplaylist)
|
44 | - [hls.representations](#hlsrepresentations)
|
45 | - [hls.xhr](#hlsxhr)
|
46 | - [Events](#events)
|
47 | - [loadedmetadata](#loadedmetadata)
|
48 | - [HLS Usage Events](#hls-usage-events)
|
49 | - [Presence Stats](#presence-stats)
|
50 | - [Use Stats](#use-stats)
|
51 | - [In-Band Metadata](#in-band-metadata)
|
52 | - [Segment Metadata](#segment-metadata)
|
53 | - [Hosting Considerations](#hosting-considerations)
|
54 | - [Known Issues](#known-issues)
|
55 | - [IE10 and Below](#ie10-and-below)
|
56 | - [IE11](#ie11)
|
57 | - [Fragmented MP4 Support](#fragmented-mp4-support)
|
58 | - [Testing](#testing)
|
59 | - [Release History](#release-history)
|
60 | - [Building](#building)
|
61 | - [Development](#development)
|
62 | - [Tools](#tools)
|
63 | - [Commands](#commands)
|
64 |
|
65 |
|
66 |
|
67 | ## Installation
|
68 | ### NPM
|
69 | To install `videojs-contrib-hls` with npm run
|
70 |
|
71 | ```bash
|
72 | npm install --save videojs-contrib-hls
|
73 | ```
|
74 |
|
75 | ### CDN
|
76 | Select a version of HLS from the [CDN](https://cdnjs.com/libraries/videojs-contrib-hls)
|
77 |
|
78 | ### Releases
|
79 | Download a release of [videojs-contrib-hls](https://github.com/videojs/videojs-contrib-hls/releases)
|
80 |
|
81 | ### Manual Build
|
82 | Download a copy of this git repository and then follow the steps in [Building](#building)
|
83 |
|
84 | ## Contributing
|
85 | See [CONTRIBUTING.md](/CONTRIBUTING.md)
|
86 |
|
87 | ## Talk to us
|
88 | Drop by our slack channel (#playback) on the [Video.js slack][slack-link].
|
89 |
|
90 | ## Getting Started
|
91 | Get a copy of [videojs-contrib-hls](#installation) and include it in your page along with video.js:
|
92 |
|
93 | ```html
|
94 | <video id=example-video width=600 height=300 class="video-js vjs-default-skin" controls>
|
95 | <source
|
96 | src="https://example.com/index.m3u8"
|
97 | type="application/x-mpegURL">
|
98 | </video>
|
99 | <script src="video.js"></script>
|
100 | <script src="videojs-contrib-hls.min.js"></script>
|
101 | <script>
|
102 | var player = videojs('example-video');
|
103 | player.play();
|
104 | </script>
|
105 | ```
|
106 |
|
107 | Check out our [live example](http://jsbin.com/vokipos/8/edit?html,output) if you're having trouble.
|
108 |
|
109 | ### Video.js 6
|
110 | With Video.js 6, by default there is no flash support. Instead, flash support is provided
|
111 | through the [videojs-flash](https://github.com/videojs/videojs-flash) plugin. If you are
|
112 | trying to use Video.js version 6 and want to include flash support, you must include
|
113 | [videojs-flash](https://github.com/videojs/videojs-flash) on your page before including
|
114 | videojs-contrib-hls
|
115 |
|
116 | ```html
|
117 | <script src="https://unpkg.com/videojs-flash/dist/videojs-flash.js"></script>
|
118 | <script src="https://unpkg.com/videojs-contrib-hls/dist/videojs-contrib-hls.js"></script>
|
119 | ```
|
120 |
|
121 | Flash, and the [videojs-flash](https://github.com/videojs/videojs-flash) plugin, are not
|
122 | required, but are recommended as a fallback option for browsers that don't have a native
|
123 | HLS player or support for [Media Source Extensions](http://caniuse.com/#feat=mediasource).
|
124 |
|
125 | ## Documentation
|
126 | [HTTP Live Streaming](https://developer.apple.com/streaming/) (HLS) has
|
127 | become a de-facto standard for streaming video on mobile devices
|
128 | thanks to its native support on iOS and Android. There are a number of
|
129 | reasons independent of platform to recommend the format, though:
|
130 |
|
131 | - Supports (client-driven) adaptive bitrate selection
|
132 | - Delivered over standard HTTP ports
|
133 | - Simple, text-based manifest format
|
134 | - No proprietary streaming servers required
|
135 |
|
136 | Unfortunately, all the major desktop browsers except for Safari are
|
137 | missing HLS support. That leaves web developers in the unfortunate
|
138 | position of having to maintain alternate renditions of the same video
|
139 | and potentially having to forego HTML-based video entirely to provide
|
140 | the best desktop viewing experience.
|
141 |
|
142 | This project addresses that situation by providing a polyfill for HLS
|
143 | on browsers that have support for [Media Source
|
144 | Extensions](http://caniuse.com/#feat=mediasource), or failing that,
|
145 | support Flash. You can deploy a single HLS stream, code against the
|
146 | regular HTML5 video APIs, and create a fast, high-quality video
|
147 | experience across all the big web device categories.
|
148 |
|
149 | Check out the [full documentation](docs/) for details on how HLS works
|
150 | and advanced configuration. A description of the [adaptive switching
|
151 | behavior](docs/bitrate-switching.md) is available, too.
|
152 |
|
153 | videojs-contrib-hls supports a bunch of HLS features. Here
|
154 | are some highlights:
|
155 |
|
156 | - video-on-demand and live playback modes
|
157 | - backup or redundant streams
|
158 | - mid-segment quality switching
|
159 | - AES-128 segment encryption
|
160 | - CEA-608 captions are automatically translated into standard HTML5
|
161 | [caption text tracks][0]
|
162 | - In-Manifest WebVTT subtitles are automatically translated into standard HTML5
|
163 | subtitle tracks
|
164 | - Timed ID3 Metadata is automatically translated into HTML5 metedata
|
165 | text tracks
|
166 | - Highly customizable adaptive bitrate selection
|
167 | - Automatic bandwidth tracking
|
168 | - Cross-domain credentials support with CORS
|
169 | - Tight integration with video.js and a philosophy of exposing as much
|
170 | as possible with standard HTML APIs
|
171 | - Stream with multiple audio tracks and switching to those audio tracks
|
172 | (see the docs folder) for info
|
173 | - Media content in
|
174 | [fragmented MP4s](https://developer.apple.com/videos/play/wwdc2016/504/)
|
175 | instead of the MPEG2-TS container format.
|
176 |
|
177 | [0]: https://developer.mozilla.org/en-US/docs/Web/HTML/Element/track
|
178 |
|
179 | ### Options
|
180 | #### How to use
|
181 |
|
182 | ##### Initialization
|
183 | You may pass in an options object to the hls source handler at player
|
184 | initialization. You can pass in options just like you would for other
|
185 | parts of video.js:
|
186 |
|
187 | ```javascript
|
188 | // html5 for html hls
|
189 | videojs(video, {html5: {
|
190 | hls: {
|
191 | withCredentials: true
|
192 | }
|
193 | }});
|
194 |
|
195 | // or
|
196 |
|
197 | // flash for flash hls
|
198 | videojs(video, {flash: {
|
199 | hls: {
|
200 | withCredentials: true
|
201 | }
|
202 | }});
|
203 |
|
204 | // or
|
205 |
|
206 | var options = {hls: {
|
207 | withCredentials: true;
|
208 | }};
|
209 |
|
210 | videojs(video, {flash: options, html5: options});
|
211 |
|
212 | ```
|
213 |
|
214 | ##### Source
|
215 | Some options, such as `withCredentials` can be passed in to hls during
|
216 | `player.src`
|
217 |
|
218 | ```javascript
|
219 |
|
220 | var player = videojs('some-video-id');
|
221 |
|
222 | player.src({
|
223 | src: 'https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8',
|
224 | type: 'application/x-mpegURL',
|
225 | withCredentials: true
|
226 | });
|
227 | ```
|
228 |
|
229 | #### List
|
230 | ##### withCredentials
|
231 | * Type: `boolean`
|
232 | * can be used as a source option
|
233 | * can be used as an initialization option
|
234 |
|
235 | When the `withCredentials` property is set to `true`, all XHR requests for
|
236 | manifests and segments would have `withCredentials` set to `true` as well. This
|
237 | enables storing and passing cookies from the server that the manifests and
|
238 | segments live on. This has some implications on CORS because when set, the
|
239 | `Access-Control-Allow-Origin` header cannot be set to `*`, also, the response
|
240 | headers require the addition of `Access-Control-Allow-Credentials` header which
|
241 | is set to `true`.
|
242 | See html5rocks's [article](http://www.html5rocks.com/en/tutorials/cors/)
|
243 | for more info.
|
244 |
|
245 | ##### useCueTags
|
246 | * Type: `boolean`
|
247 | * can be used as an initialization option
|
248 |
|
249 | When the `useCueTags` property is set to `true,` a text track is created with
|
250 | label 'ad-cues' and kind 'metadata'. The track is then added to
|
251 | `player.textTracks()`. Changes in active cue may be
|
252 | tracked by following the Video.js cue points API for text tracks. For example:
|
253 |
|
254 | ```javascript
|
255 | let textTracks = player.textTracks();
|
256 | let cuesTrack;
|
257 |
|
258 | for (let i = 0; i < textTracks.length; i++) {
|
259 | if (textTracks[i].label === 'ad-cues') {
|
260 | cuesTrack = textTracks[i];
|
261 | }
|
262 | }
|
263 |
|
264 | cuesTrack.addEventListener('cuechange', function() {
|
265 | let activeCues = cuesTrack.activeCues;
|
266 |
|
267 | for (let i = 0; i < activeCues.length; i++) {
|
268 | let activeCue = activeCues[i];
|
269 |
|
270 | console.log('Cue runs from ' + activeCue.startTime +
|
271 | ' to ' + activeCue.endTime);
|
272 | }
|
273 | });
|
274 | ```
|
275 |
|
276 | ##### overrideNative
|
277 | * Type: `boolean`
|
278 | * can be used as an initialization option
|
279 |
|
280 | Try to use videojs-contrib-hls even on platforms that provide some
|
281 | level of HLS support natively. There are a number of platforms that
|
282 | *technically* play back HLS content but aren't very reliable or are
|
283 | missing features like CEA-608 captions support. When `overrideNative`
|
284 | is true, if the platform supports Media Source Extensions
|
285 | videojs-contrib-hls will take over HLS playback to provide a more
|
286 | consistent experience.
|
287 |
|
288 | __NOTE__: If you use this option, you must also set
|
289 | `videojs.options.html5.nativeAudioTracks` and
|
290 | `videojs.options.html5.nativeVideoTracks` to
|
291 | `false`. videojs-contrib-hls relies on audio and video tracks to play
|
292 | streams with alternate audio and requires additional capabilities only
|
293 | supported by non-native tracks in video.js.
|
294 |
|
295 | ##### blacklistDuration
|
296 | * Type: `number`
|
297 | * can be used as an initialization option
|
298 |
|
299 | When the `blacklistDuration` property is set to a time duration in seconds,
|
300 | if a playlist is blacklisted, it will be blacklisted for a period of that
|
301 | customized duration. This enables the blacklist duration to be configured
|
302 | by the user.
|
303 |
|
304 | ##### bandwidth
|
305 | * Type: `number`
|
306 | * can be used as an initialization option
|
307 |
|
308 | When the `bandwidth` property is set (bits per second), it will be used in
|
309 | the calculation for initial playlist selection, before more bandwidth
|
310 | information is seen by the player.
|
311 |
|
312 | ### Runtime Properties
|
313 | Runtime properties are attached to the tech object when HLS is in
|
314 | use. You can get a reference to the HLS source handler like this:
|
315 |
|
316 | ```javascript
|
317 | var hls = player.tech({ IWillNotUseThisInPlugins: true }).hls;
|
318 | ```
|
319 |
|
320 | If you *were* thinking about modifying runtime properties in a
|
321 | video.js plugin, we'd recommend you avoid it. Your plugin won't work
|
322 | with videos that don't use videojs-contrib-hls and the best plugins
|
323 | work across all the media types that video.js supports. If you're
|
324 | deploying videojs-contrib-hls on your own website and want to make a
|
325 | couple tweaks though, go for it!
|
326 |
|
327 | #### hls.playlists.master
|
328 | Type: `object`
|
329 |
|
330 | An object representing the parsed master playlist. If a media playlist
|
331 | is loaded directly, a master playlist with only one entry will be
|
332 | created.
|
333 |
|
334 | #### hls.playlists.media
|
335 | Type: `function`
|
336 |
|
337 | A function that can be used to retrieve or modify the currently active
|
338 | media playlist. The active media playlist is referred to when
|
339 | additional video data needs to be downloaded. Calling this function
|
340 | with no arguments returns the parsed playlist object for the active
|
341 | media playlist. Calling this function with a playlist object from the
|
342 | master playlist or a URI string as specified in the master playlist
|
343 | will kick off an asynchronous load of the specified media
|
344 | playlist. Once it has been retreived, it will become the active media
|
345 | playlist.
|
346 |
|
347 | #### hls.segmentXhrTime
|
348 | Type: `number`
|
349 |
|
350 | The number of milliseconds it took to download the last media segment.
|
351 | This value is updated after each segment download completes.
|
352 |
|
353 | #### hls.bandwidth
|
354 | Type: `number`
|
355 |
|
356 | The number of bits downloaded per second in the last segment download.
|
357 | This value is used by the default implementation of `selectPlaylist`
|
358 | to select an appropriate bitrate to play.
|
359 |
|
360 | Before the first video segment has been downloaded, it's hard to
|
361 | estimate bandwidth accurately. The HLS tech uses a heuristic based on
|
362 | the playlist download times to do this estimation by default. If you
|
363 | have a more accurate source of bandwidth information, you can override
|
364 | this value as soon as the HLS tech has loaded to provide an initial
|
365 | bandwidth estimate.
|
366 |
|
367 | #### hls.bytesReceived
|
368 | Type: `number`
|
369 |
|
370 | The total number of content bytes downloaded by the HLS tech.
|
371 |
|
372 | #### hls.selectPlaylist
|
373 | Type: `function`
|
374 |
|
375 | A function that returns the media playlist object to use to download
|
376 | the next segment. It is invoked by the tech immediately before a new
|
377 | segment is downloaded. You can override this function to provide your
|
378 | adaptive streaming logic. You must, however, be sure to return a valid
|
379 | media playlist object that is present in `player.hls.master`.
|
380 |
|
381 | Overridding this function with your own is very powerful but is overkill
|
382 | for many purposes. Most of the time, you should use the much simpler
|
383 | function below to selectively enable or disable a playlist from the
|
384 | adaptive streaming logic.
|
385 |
|
386 | #### hls.representations
|
387 | Type: `function`
|
388 |
|
389 | It is recommended to include the [videojs-contrib-quality-levels](https://github.com/videojs/videojs-contrib-quality-levels) plugin to your page so that videojs-contrib-hls will automatically populate the QualityLevelList exposed on the player by the plugin. You can access this list by calling `player.qualityLevels()`. See the [videojs-contrib-quality-levels project page](https://github.com/videojs/videojs-contrib-quality-levels) for more information on how to use the api.
|
390 |
|
391 | Example, only enabling representations with a width greater than or equal to 720:
|
392 |
|
393 | ```javascript
|
394 | var qualityLevels = player.qualityLevels();
|
395 |
|
396 | for (var i = 0; i < qualityLevels.length; i++) {
|
397 | var quality = qualityLevels[i];
|
398 | if (quality.width >= 720) {
|
399 | quality.enabled = true;
|
400 | } else {
|
401 | quality.enabled = false;
|
402 | }
|
403 | }
|
404 | ```
|
405 |
|
406 | If including [videojs-contrib-quality-levels](https://github.com/videojs/videojs-contrib-quality-levels) is not an option, you can use the representations api. To get all of the available representations, call the `representations()` method on `player.hls`. This will return a list of plain objects, each with `width`, `height`, `bandwidth`, and `id` properties, and an `enabled()` method.
|
407 |
|
408 | ```javascript
|
409 | player.hls.representations();
|
410 | ```
|
411 |
|
412 | To see whether the representation is enabled or disabled, call its `enabled()` method with no arguments. To set whether it is enabled/disabled, call its `enabled()` method and pass in a boolean value. Calling `<representation>.enabled(true)` will allow the adaptive bitrate algorithm to select the representation while calling `<representation>.enabled(false)` will disallow any selection of that representation.
|
413 |
|
414 | Example, only enabling representations with a width greater than or equal to 720:
|
415 |
|
416 | ```javascript
|
417 | player.hls.representations().forEach(function(rep) {
|
418 | if (rep.width >= 720) {
|
419 | rep.enabled(true);
|
420 | } else {
|
421 | rep.enabled(false);
|
422 | }
|
423 | });
|
424 | ```
|
425 |
|
426 | #### hls.xhr
|
427 | Type: `function`
|
428 |
|
429 | The xhr function that is used by HLS internally is exposed on the per-
|
430 | player `hls` object. While it is possible, we do not recommend replacing
|
431 | the function with your own implementation. Instead, the `xhr` provides
|
432 | the ability to specify a `beforeRequest` function that will be called
|
433 | with an object containing the options that will be used to create the
|
434 | xhr request.
|
435 |
|
436 | Example:
|
437 | ```javascript
|
438 | player.hls.xhr.beforeRequest = function(options) {
|
439 | options.uri = options.uri.replace('example.com', 'foo.com');
|
440 |
|
441 | return options;
|
442 | };
|
443 | ```
|
444 |
|
445 | The global `videojs.Hls` also exposes an `xhr` property. Specifying a
|
446 | `beforeRequest` function on that will allow you to intercept the options
|
447 | for *all* requests in every player on a page. For consistency across
|
448 | browsers the video source should be set at runtime once the video player
|
449 | is ready.
|
450 |
|
451 | Example
|
452 | ```javascript
|
453 | videojs.Hls.xhr.beforeRequest = function(options) {
|
454 | /*
|
455 | * Modifications to requests that will affect every player.
|
456 | */
|
457 |
|
458 | return options;
|
459 | };
|
460 |
|
461 | var player = videojs('video-player-id');
|
462 | player.ready(function() {
|
463 | this.src({
|
464 | src: 'https://d2zihajmogu5jn.cloudfront.net/bipbop-advanced/bipbop_16x9_variant.m3u8',
|
465 | type: 'application/x-mpegURL',
|
466 | });
|
467 | });
|
468 | ```
|
469 |
|
470 | For information on the type of options that you can modify see the
|
471 | documentation at [https://github.com/Raynos/xhr](https://github.com/Raynos/xhr).
|
472 |
|
473 | ### Events
|
474 | Standard HTML video events are handled by video.js automatically and
|
475 | are triggered on the player object.
|
476 |
|
477 | #### loadedmetadata
|
478 |
|
479 | Fired after the first segment is downloaded for a playlist. This will not happen
|
480 | until playback if video.js's `metadata` setting is `none`
|
481 |
|
482 | ### HLS Usage Events
|
483 |
|
484 | Usage tracking events are fired when we detect a certain HLS feature, encoding setting,
|
485 | or API is used. These can be helpful for analytics, and to pinpoint the cause of HLS errors.
|
486 | For instance, if errors are being fired in tandem with a usage event indicating that the
|
487 | player was playing an AES encrypted stream, then we have a possible avenue to explore when
|
488 | debugging the error.
|
489 |
|
490 | Note that although these usage events are listed below, they may change at any time without
|
491 | a major version change.
|
492 |
|
493 | HLS usage events are triggered on the tech with the exception of the 3 hls-reload-error
|
494 | events, which are triggered on the player.
|
495 |
|
496 | #### Presence Stats
|
497 |
|
498 | Each of the following usage events are fired once per source if (and when) detected:
|
499 |
|
500 | | Name | Description |
|
501 | | ------------- | ------------- |
|
502 | | hls-webvtt | master manifest has at least one segmented WebVTT playlist |
|
503 | | hls-aes | a playlist is AES encrypted |
|
504 | | hls-fmp4 | a playlist used fMP4 segments |
|
505 | | hls-demuxed | audio and video are demuxed by default |
|
506 | | hls-alternate-audio | alternate audio available in the master manifest |
|
507 | | hls-playlist-cue-tags | a playlist used cue tags (see useCueTags(#usecuetags) for details) |
|
508 |
|
509 | #### Use Stats
|
510 |
|
511 | Each of the following usage events are fired per use:
|
512 |
|
513 | | Name | Description |
|
514 | | ------------- | ------------- |
|
515 | | hls-gap-skip | player skipped a gap in the buffer |
|
516 | | hls-player-access | player.hls was accessed |
|
517 | | hls-audio-change | a user selected an alternate audio stream |
|
518 | | hls-rendition-disabled | a rendition was disabled |
|
519 | | hls-rendition-enabled | a rendition was enabled |
|
520 | | hls-rendition-blacklisted | a rendition was blacklisted |
|
521 | | hls-timestamp-offset | a timestamp offset was set in HLS (can identify discontinuities) |
|
522 | | hls-unknown-waiting | the player stopped for an unknown reason and we seeked to current time try to address it |
|
523 | | hls-live-resync | playback fell off the back of a live playlist and we resynced to the live point |
|
524 | | hls-video-underflow | we seeked to current time to address video underflow |
|
525 | | hls-error-reload-initialized | the reloadSourceOnError plugin was initialized |
|
526 | | hls-error-reload | the reloadSourceOnError plugin reloaded a source |
|
527 | | hls-error-reload-canceled | an error occurred too soon after the last reload, so we didn't reload again (to prevent error loops) |
|
528 |
|
529 |
|
530 | ### In-Band Metadata
|
531 | The HLS tech supports [timed
|
532 | metadata](https://developer.apple.com/library/ios/#documentation/AudioVideo/Conceptual/HTTP_Live_Streaming_Metadata_Spec/Introduction/Introduction.html)
|
533 | embedded as [ID3 tags](http://id3.org/id3v2.3.0). When a stream is
|
534 | encountered with embedded metadata, an [in-band metadata text
|
535 | track](https://html.spec.whatwg.org/multipage/embedded-content.html#text-track-in-band-metadata-track-dispatch-type)
|
536 | will automatically be created and populated with cues as they are
|
537 | encountered in the stream. UTF-8 encoded
|
538 | [TXXX](http://id3.org/id3v2.3.0#User_defined_text_information_frame)
|
539 | and [WXXX](http://id3.org/id3v2.3.0#User_defined_URL_link_frame) ID3
|
540 | frames are mapped to cue points and their values set as the cue
|
541 | text. Cues are created for all other frame types and the data is
|
542 | attached to the generated cue:
|
543 |
|
544 | ```javascript
|
545 | cue.value.data
|
546 | ```
|
547 |
|
548 | There are lots of guides and references to using text tracks [around
|
549 | the web](http://www.html5rocks.com/en/tutorials/track/basics/).
|
550 |
|
551 | ### Segment Metadata
|
552 | You can get metadata about the segments currently in the buffer by using the `segment-metadata`
|
553 | text track. You can get the metadata of the currently rendered segment by looking at the
|
554 | track's `activeCues` array. The metadata will be attached to the `cue.value` property and
|
555 | will have this structure
|
556 |
|
557 | ```javascript
|
558 | cue.value = {
|
559 | uri, // The Segment uri
|
560 | timeline, // Timeline of the segment for detecting discontinuities
|
561 | playlist, // The Playlist uri
|
562 | start, // Segment start time
|
563 | end // Segment end time
|
564 | };
|
565 | ```
|
566 |
|
567 | Example:
|
568 | Detect when a change in quality is rendered on screen
|
569 | ```javascript
|
570 | let tracks = player.textTracks();
|
571 | let segmentMetadataTrack;
|
572 |
|
573 | for (let i = 0; i < tracks.length; i++) {
|
574 | if (tracks[i].label === 'segment-metadata') {
|
575 | segmentMetadataTrack = tracks[i];
|
576 | }
|
577 | }
|
578 |
|
579 | let previousPlaylist;
|
580 |
|
581 | if (segmentMetadataTrack) {
|
582 | segmentMetadataTrack.on('cuechange', function() {
|
583 | let activeCue = segmentMetadataTrack.activeCues[0];
|
584 |
|
585 | if (activeCue) {
|
586 | if (previousPlaylist !== activeCue.value.playlist) {
|
587 | console.log('Switched from rendition ' + previousPlaylist +
|
588 | ' to rendition ' + activeCue.value.playlist);
|
589 | }
|
590 | previousPlaylist = activeCue.value.playlist;
|
591 | }
|
592 | });
|
593 | }
|
594 | ```
|
595 |
|
596 | ## Hosting Considerations
|
597 | Unlike a native HLS implementation, the HLS tech has to comply with
|
598 | the browser's security policies. That means that all the files that
|
599 | make up the stream must be served from the same domain as the page
|
600 | hosting the video player or from a server that has appropriate [CORS
|
601 | headers](https://developer.mozilla.org/en-US/docs/HTTP/Access_control_CORS)
|
602 | configured. Easy [instructions are
|
603 | available](http://enable-cors.org/server.html) for popular webservers
|
604 | and most CDNs should have no trouble turning CORS on for your account.
|
605 |
|
606 |
|
607 | ## Known Issues
|
608 | Issues that are currenty know about with workarounds. If you want to
|
609 | help find a solution that would be appreciated!
|
610 |
|
611 | ### IE10 and Below
|
612 | As of version 5.0.0, IE10 and below are no longer supported.
|
613 |
|
614 | ### IE11
|
615 | In some IE11 setups there are issues working with its native HTML
|
616 | SourceBuffers functionality. This leads to various issues, such as
|
617 | videos stopping playback with media decode errors. The known workaround
|
618 | for this issues is to force the player to use flash when running on IE11.
|
619 |
|
620 | ### Fragmented MP4 Support
|
621 | Edge has native support for HLS but only in the MPEG2-TS container. If
|
622 | you attempt to play an HLS stream with fragmented MP4 segments, Edge
|
623 | will stall. Fragmented MP4s are only supported on browser that have
|
624 | [Media Source Extensions](http://caniuse.com/#feat=mediasource) available.
|
625 |
|
626 | ### Testing
|
627 |
|
628 | For testing, you run `npm run test`. This will run tests using any of the
|
629 | browsers that karma-detect-browsers detects on your machine.
|
630 |
|
631 | ## Release History
|
632 | Check out the [changelog](CHANGELOG.md) for a summary of each release.
|
633 |
|
634 | ## Building
|
635 | To build a copy of videojs-contrib-hls run the following commands
|
636 |
|
637 | ```bash
|
638 | git clone https://github.com/videojs/videojs-contrib-hls
|
639 | cd videojs-contrib-hls
|
640 | npm i
|
641 | npm run build
|
642 | ```
|
643 |
|
644 | videojs-contrib-hls will have created all of the files for using it in a dist folder
|
645 |
|
646 | ## Development
|
647 |
|
648 | ### Tools
|
649 | * Download stream locally with the [HLS Fetcher](https://github.com/imbcmdth/hls-fetcher)
|
650 | * Simulate errors with [Murphy](https://github.com/mrocajr/murphy)
|
651 |
|
652 | ### Commands
|
653 | All commands for development are listed in the `package.json` file and are run using
|
654 | ```bash
|
655 | npm run <command>
|
656 | ```
|
657 |
|
658 | [slack-icon]: http://slack.videojs.com/badge.svg
|
659 | [slack-link]: http://slack.videojs.com
|
660 | [travis-icon]: https://travis-ci.org/videojs/videojs-contrib-hls.svg?branch=master
|
661 | [travis-link]: https://travis-ci.org/videojs/videojs-contrib-hls
|