@mux/mux-player 1.0.0-beta.0 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -9,359 +9,33 @@
9
9
 
10
10
  `<mux-player>` is the official Mux-flavored video player web component.
11
11
 
12
- The player UI is built on [`<media-chrome>`](https://github.com/muxinc/media-chrome/) and [`<mux-video>`](https://github.com/muxinc/elements/tree/main/packages/mux-video) drives the core video logic used to play Mux Video content that Just Works.
13
-
14
- Be sure to check out our [official Mux documentation](https://docs.mux.com/guides/video/mux-player), too!
12
+ The player UI is built on [Media Chrome](https://media-chrome.org) and [`<mux-video>`](../mux-video) drives the core video logic used to play Mux Video content.
15
13
 
16
14
  # Installation
17
15
 
18
- If you're using `npm` or `yarn`, install that way:
19
-
20
- ## Package manager
21
-
22
- ```
23
- yarn add @mux/mux-player
16
+ ```shell
17
+ npm install @mux/mux-player-react
24
18
  ```
25
19
 
26
20
  or
27
21
 
28
- ```
29
- npm i @mux/mux-player
30
- ```
31
-
32
- Then, import the library into your application with either `import` or `require`:
33
-
34
- ```js
35
- import '@mux/mux-player';
36
- ```
37
-
38
- or
39
-
40
- ```js
41
- require('@mux/mux-player');
42
- ```
43
-
44
- ## CDN option
45
-
46
- Alternatively, use the CDN hosted version of this package:
47
-
48
- ```html
49
- <script src="https://unpkg.com/@mux/mux-player"></script>
50
- ```
51
-
52
- If you are using ECMAScript modules, you can also load the `mux-player.mjs` file with `type=module`:
53
-
54
- ```html
55
- <script type="module" src="https://unpkg.com/@mux/mux-player/dist/mux-player.mjs"></script>
56
- ```
57
-
58
- ## Features and benefits
59
-
60
- `<mux-player>` is a fully functional Video Player for the web with dirt simple integration to [Mux Video](https://docs.mux.com/guides/video) and [Mux Data](https://docs.mux.com/guides/data/monitor-hls-js).
61
-
62
- `<mux-player>` provides a responsive UI based on player dimensions and stream type, automatic thumbnail previews and poster images, and built-in integration with Mux Data.
63
-
64
- `<mux-player>` will use the optimal [Hls.js](https://github.com/video-dev/hls.js) settings for Mux Video so you don't have to worry about that. `<mux-player>` will also periodically test new versions of Hls.js and upgrade to known stable versions so you don't have to worry about upgrading to a new version of Hls.js yourself.
65
-
66
- ## Usage
67
-
68
- Loading this library in the browser will register a [custom web component](https://developer.mozilla.org/en-US/docs/Web/Web_Components) for `<mux-player>`.
69
-
70
- Now you are free to use this web component in your HTML, just as you would with the HTML5 `<video>` element.
71
-
72
- ```html
73
- <body>
74
- <p></p>
75
-
76
- <mux-player
77
- playback-id="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe"
78
- metadata-video-title="Big Buck Bunny"
79
- metadata-viewer-user-id="user-id-1234"
80
- stream-type="on-demand"
81
- ></mux-player>
82
- </body>
83
- ```
84
-
85
- ### Metadata
86
-
87
- To go above and beyond `metadata-*` attributes
88
-
89
- To set other available metadata fields use the `metadata` property on the `<mux-player>` element like so:
90
-
91
- ```html
92
- <mux-player
93
- playback-id="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe"
94
- env-key="mux-data-env-key"
95
- metadata-video-title="Big Buck Bunny"
96
- metadata-viewer-user-id="user-id-1234"
97
- >
98
- </mux-player>
99
-
100
- <script>
101
- const muxVideo = document.querySelector('mux-player');
102
- muxVideo.metadata = {
103
- experiment_name: 'landing_page_v3',
104
- video_content_type: 'clip',
105
- video_series: 'season 1',
106
- };
107
- </script>
108
- ```
109
-
110
- Take a look at the [metadata guide](https://docs.mux.com/guides/data/make-your-data-actionable-with-metadata) to view an exhaustive list of available values.
111
-
112
- ### Chromecast
113
-
114
- Enable the [Google Cast](https://developers.google.com/cast) button in the controlbar by dropping in the `<script>` tag below in the `<head>` of your webpage.
115
-
116
- ```html
117
- <script defer src="https://www.gstatic.com/cv/js/sender/v1/cast_sender.js?loadCastFramework=1"></script>
118
- ```
119
-
120
- ### Hiding controls
121
-
122
- By default, Mux Player will show all the controls associated with the current player size and stream type.
123
-
124
- To hide certain controls, use CSS variables like this:
125
- `--play-button` will control the display of the play button. Set it to `none` to hide it completely.
126
-
127
- ```css
128
- mux-player {
129
- --play-button: none;
130
- }
22
+ ```shell
23
+ yarn add @mux/mux-player-react
131
24
  ```
132
25
 
133
- CSS vars can also be passed inline
134
-
135
- ```html
136
- <mux-player style="--play-button: none;"></mux-player>
137
- ```
138
-
139
- #### Controls sections
140
-
141
- It's possible to target specific sections of the player by prefixing the CSS vars.
142
- The following sections are available:
143
-
144
- - `top` the top control bar that shows on the small player size
145
- - `center` the center controls that show the seek forward/backward button and play button
146
- - `bottom` the bottom control bar
147
-
148
- ```html
149
- <mux-player style="--center-controls: none; --top-captions-button: none;"></mux-player>
150
- ```
151
-
152
- #### Available CSS variables
153
-
154
- The below CSS selector shows all available CSS vars for hiding, each one can be prefixed with a section.
155
-
156
- ```css
157
- mux-player {
158
- /* Hide all controls at once */
159
- --controls: none;
160
-
161
- /* Target all sections by excluding the section prefix */
162
- --play-button: none;
163
- --seek-live-button: none;
164
- --seek-backward-button: none;
165
- --seek-forward-button: none;
166
- --mute-button: none;
167
- --captions-button: none;
168
- --airplay-button: none;
169
- --pip-button: none;
170
- --fullscreen-button: none;
171
- --cast-button: none;
172
- --playback-rate-button: none;
173
- --volume-range: none;
174
- --time-range: none;
175
- --time-display: none;
176
- --duration-display: none;
177
-
178
- /* Target a specific section by prefixing the CSS var with (top|center|bottom) */
179
- --center-controls: none;
180
- --bottom-play-button: none;
181
- }
182
- ```
183
-
184
- ### CSS Parts
185
-
186
- Mux Player uses a [shadow DOM](https://developer.mozilla.org/en-US/docs/Web/Web_Components/Using_shadow_DOM)
187
- to encapsulate its styles and behaviors.
188
- As a result, it's not possible to target its internals with the usual CSS selectors.
189
- Instead, some components expose **parts** that can be targeted with the [CSS part selector](https://developer.mozilla.org/en-US/docs/Web/CSS/::part)
190
- , or `::part()`.
191
-
192
- ```html
193
- <style>
194
- mux-player::part(center play button) {
195
- display: none;
196
- }
197
- </style>
198
- <mux-player playback-id="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe"></mux-player>
199
- ```
200
-
201
- ### Controls Backdrop Color
202
-
203
- We expose a CSS variable to set the controls backdrop color.
204
-
205
- ```css
206
- mux-player {
207
- --controls-backdrop-color: rgb(0 0 0 / 0%);
208
- }
209
- ```
210
-
211
- Turning this off completely has implications on the accessibility of the controls as they may not meet [the contrast ratio requirements for WCAG 2.1](https://www.w3.org/TR/WCAG/#contrast-minimum) without it.
212
-
213
- Supported **parts**:
214
- `seek-live`, `layer`, `media-layer`, `poster-layer`, `vertical-layer`, `centered-layer`, `gesture-layer`,
215
- `top`, `center`, `bottom`, `play`, `button`, `seek-backward`, `seek-forward`, `mute`,
216
- `captions`, `airplay`, `pip`, `cast`, `fullscreen`, `playback-rate`, `volume`, `range`, `time`, `display`
217
-
218
- CSS parts allow you to style each part individually with a selector like `::part(center play button)`
219
- or target multiple elements if the part is assigned to multiple elements internally, usage `::part(button)`.
220
- Every CSS property can be declared in the selector, this makes it a very powerful API.
221
-
222
- ### hotkeys
223
-
224
- Offers a way to turn off keyboard shortcuts that should not be enabled.
225
- The `hotkeys` attribute accepts a blocklist as a space separated string.
226
-
227
- Supported **tokens**:
228
- `nof`, `nok`, `nom`, `noarrowleft`, `noarrowright`, `nospace`
229
-
230
- ```html
231
- <mux-player playback-id="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe" hotkeys="noarrowleft noarrowright"></mux-player>
232
- ```
233
-
234
- #### Default hotkeys
235
-
236
- | Key | Behavior |
237
- | ----- | ----------------- |
238
- | Space | Toggle Playback |
239
- | `k` | Toggle Playback |
240
- | `m` | Toggle mute |
241
- | `f` | Toggle fullscreen |
242
- | ⬅ | Seek back 10s |
243
- | ➡ | Seek forward 10s |
244
-
245
- ### prefer-mse
246
-
247
- By default `<mux-player>` will try to use native playback via the underlying `<video/>` tag whenever possible. However, it can also instead use an in-code player when the browser browser supports [Media Source Extension](https://developer.mozilla.org/en-US/docs/Web/API/Media_Source_Extensions_API). This includes MSE in Mac OS Safari.
248
-
249
- If you prefer to use the in-code MSE-based engine (currently hls.js) whenever possible, then pass in the `prefer-mse` attribute.
26
+ # Usage
250
27
 
251
28
  ```html
252
29
  <mux-player
253
30
  playback-id="DS00Spx1CV902MCtPj5WknGlR102V5HFkDe"
254
31
  metadata-video-title="Big Buck Bunny"
255
32
  metadata-viewer-user-id="user-id-1234"
256
- prefer-mse
257
- >
258
- </mux-player>
33
+ stream-type="on-demand"
34
+ ></mux-player>
259
35
  ```
260
36
 
261
- ### Attributes
262
-
263
- | Attribute | Type | Description | Default |
264
- | ----------------------------- | ------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------- |
265
- | `playback-id` | `string` | The playback ID for your Mux Asset or Mux Live Stream. This will also be used for automatically assigning a [poster image](https://docs.mux.com/guides/video/get-images-from-a-video) and (thumbnail previews)[https://docs.mux.com/guides/video/create-timeline-hover-previews]. For more, check out the [Mux Docs](https://docs.mux.com/guides/video/play-your-videos#1-get-your-playback-id). | N/A |
266
- | `env-key` | `string` | Your Mux Data environment key. Note that this is different than your API Key. Get your env key from the "Mux Data" part of your [Mux Environments Dashboard](https://dashboard.mux.com/environments). If undefined, the environment will be inferred based on your Mux Video asset. | `undefined` |
267
- | `playback-token` | `string` | The playback token for signing the `src` URL. | N/A |
268
- | `thumbnail-token` | `string` | The thumbnail token for signing the `poster` URL. | N/A |
269
- | `storyboard-token` | `string` | The storyboard token for signing the storyboard URL. | N/A |
270
- | `stream-type` | `"on-demand" \| "live" \| "ll-live" \| "live:dvr" \| "ll-live:dvr"` | The type of stream associated with your Mux Asset. Used to determine what UI/controls to show and what optimizations to make for playback. | `"on-demand"` |
271
- | `audio` | `boolean` | Indicate that you want an "audio only" UI/chrome. This may be used for audio-only assets or audio+video assets. | `false` |
272
- | `metadata-video-title` | `string` | This is an arbitrary title for your video that will be passed in as metadata into Mux Data. Adding a title will give you useful context in your Mux Data dashboard. (optional, but encouraged) | N/A |
273
- | `metadata-viewer-user-id` | `string` | If you have a logged-in user this should be an anonymized ID value that maps back to the user in your database. Take care to not expose personal identifiable information like names, usernames or email addresses. (optional, but encouraged) | N/A |
274
- | `metadata-video-id` | `string` | This is an arbitrary ID that should map back to a record of this video in your database. | N/A |
275
- | `debug` | `boolean` | Enables debug mode for the underlying playback engine (currently hls.js) and mux-embed, providing additional information in the console. | `false` |
276
- | `start-time` | `number` (seconds) | Specify where in the media's timeline you want playback to start. | `0` |
277
- | `thumbnail-time` | `number` (seconds) | Offset for the poster image you want to show before loading media. If no `thumbnail-time` is specified, `start-time` will be used by default. NOTE: This feature currently cannot be used with `thumbnail-token`. | `0` |
278
- | `prefer-mse` | `boolean` | Use the underlying playback engine (currently hls.js), even if native playback is supported (e.g. in Safari). For more, see the section on [`prefer-mse`](#prefer-mse) | `false` |
279
- | `default-hidden-captions` | `boolean` | Hide captions by default instead of showing them on initial load (when available) | `false` |
280
- | `default-show-remaining-time` | `boolean` | Show remaining playback time (instead of current playback time) by default | `false` |
281
- | `forward-seek-offset` | `number` (seconds) | Offset applied to the forward seek button | `10` |
282
- | `backward-seek-offset` | `number` (seconds) | Offset applied to the backward seek button | `10` |
283
- | `primary-color` | (Any valid CSS color style) | The primary color used by the player | N/A |
284
- | `secondary-color` | (Any valid CSS color style) | The secondary color used by the player | N/A |
285
- | `volume` | `number` (0-1) | Sets the volume of the player from 0 to 1. | Varies |
286
- | `muted` | `boolean` | Toggles the muted state of the player. | Varies |
287
- | `autoplay` | `boolean` | Toggles whether or not media should auto-play when initially loaded | false |
288
- | `playbackrate` | `number` | Applies a multiplier to the media's playback rate, either speeding it up or slowing it down. | `1` |
289
- | `playbackrates` | `string` | A space separated string of playback rates used by the playback rate button. | N/A |
290
- | `loop` | `boolean` | Automatically loop playback of your media when it finishes. | `false` |
291
- | `title` | `string` | Show the title for your content. | `""` |
292
- | `poster` | `string` (URL) | Assigns a poster image URL. Will use the automatically generated poster based on your playback-id by default. | Derived |
293
- | `beacon-collection-domain` | `string` (domain name) | Assigns a custom domain to be used for Mux Data collection. | N/A |
294
- | `custom-domain` | `string` (domain name) | Assigns a custom domain to be used for Mux Video. | N/A |
295
- | `nohotkeys` | `boolean` | Toggles keyboard shortcut (hot keys) support when focus in inside the player | `false` |
296
- | `hotkeys` | `string` | Offers a way to disable certain keyboard shortcuts. For more, see the section on [`hotkeys`](#hotkeys) | N/A |
297
-
298
- ### Methods
299
-
300
- | Method | Description |
301
- | --------- | ----------------------------- |
302
- | `play()` | Begins playback of the media. |
303
- | `pause()` | Pauses the media playback. |
304
-
305
- ### Properties
306
-
307
- | Prop | Description | Default |
308
- | --------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------- |
309
- | `autoplay` | A `Boolean` that reflects the `autoplay` HTML attribute, indicating whether playback should automatically begin as soon as enough media is available to do so without interruption. | `false` |
310
- | `buffered` <sub><sup>Read only</sup></sub> | Returns a `TimeRanges` object that indicates the ranges of the media source that the browser has buffered (if any) at the moment the buffered property is accessed. | `undefined` |
311
- | `crossOrigin` | A DOMString indicating the CORS setting for this media element. | `null` |
312
- | `currentTime` | A double-precision floating-point value indicating the current playback time in seconds; if the media has not started to play and has not been seeked, this value is the media's initial playback time. Setting this value seeks the media to the new time. The time is specified relative to the media's timeline. | `0` |
313
- | `defaultMuted` | Is a `Boolean` that reflects the `muted` HTML attribute, determines whether audio is muted by default. `true` if the audio output should be muted by default and `false` otherwise. | `false` |
314
- | `defaultPlaybackRate` | Is a double that reflects the `playbackrate` HTML attribute, it indicates the default playback rate for the media. | `1` |
315
- | `duration` <sub><sup>Read only</sup></sub> | A read-only double-precision floating-point value indicating the total duration of the media in seconds. If no media data is available, the returned value is `NaN`. If the media is of indefinite length (such as streamed live media, a WebRTC call's media, or similar), the value is `+Infinity`. | `NaN` |
316
- | `defaultHiddenCaptions` | Hide captions by default instead of showing them on initial load (when available) | `false` |
317
- | `defaultShowRemainingTime` | Show remaining playback time (instead of current playback time) by default | `false` |
318
- | `ended` <sub><sup>Read only</sup></sub> | Returns a `Boolean` that indicates whether the media element has finished playing. | `false` |
319
- | `loop` | A `Boolean` that reflects the `loop` HTML attribute, which indicates whether the media element should start over when it reaches the end. | `false` |
320
- | `nohotkeys` | A `Boolean` that reflects the `nohotkeys` HTML attribute, which indicates whether Mux Player accepts keboard shortcuts. | `false` |
321
- | `hotkeys` | Is a read-only `DOMTokenList` similar to `classList` which offers a way to turn off keyboard shortcuts. For more, see the section on [`hotkeys`](#hotkeys) | `''` |
322
- | `metadata` | The metadata property can be used to set the Mux Data metadata properties in an easy way. Take a look at the [metadata guide](https://docs.mux.com/guides/data/make-your-data-actionable-with-metadata) to view an exhaustive list of available values. | `{}` |
323
- | `muted` | Is a `Boolean` that determines whether audio is muted. `true` if the audio is muted and `false` otherwise. | `false` |
324
- | `paused` <sub><sup>Read only</sup></sub> | Returns a `Boolean` that indicates whether the media element is paused. | `true` |
325
- | `playbackRate` | Is a double that indicates the rate at which the media is being played back. | `1` |
326
- | `playbackRates` | Is an array of numbers that will be used by the playback rate button while toggling through rates. | N/A |
327
- | `playsInline` | A Boolean attribute indicating that the video is to be played "inline", that is within the element's playback area. Note that the absence of this attribute does not imply that the video will always be played in fullscreen. | `false` |
328
- | `preload` | Is a `DOMString` that reflects the `preload` HTML attribute, indicating what data should be preloaded, if any. Possible values are: `none`, `metadata`, `auto`. | `undefined` |
329
- | `src` | Is a `String` that reflects the `src` HTML attribute, which contains the URL of a media resource to use. | `undefined` |
330
- | `title` | `String` that specifies the title text you want displayed for your video. | `0` |
331
- | `startTime` | `Number` that specifies where in the media's timeline you want playback to start (in seconds). | `0` |
332
- | `thumbnailTime` | `Number` offset (in seconds) for the poster image you want to show before loading media. If no `thumbnailTime` is specified, `startTime` will be used by default. NOTE: This feature currently cannot be used with `tokens.thumbnail`. | `0` |
333
- | `tokens` | The tokens property accepts an object with the following signature `{ playback: string, thumbnail: string, storyboard: string }`. Use it to set all the signing URL tokens in one go. | `{}` |
334
- | `videoHeight` <sub><sup>Read only</sup></sub> | Returns an unsigned integer value indicating the intrinsic height of the resource in CSS pixels, or 0 if no media is available yet. | `0` |
335
- | `videoWidth` <sub><sup>Read only</sup></sub> | Returns an unsigned integer value indicating the intrinsic width of the resource in CSS pixels, or 0 if no media is available yet. | `0` |
336
- | `volume` | Is a double indicating the audio volume, from 0.0 (silent) to 1.0 (loudest). | `1` |
337
- | `customDomain` | Is a `String` that assigns a custom domain to be used for Mux Video. | `undefined` |
338
-
339
- ### Events
37
+ # Docs
340
38
 
341
- `<mux-player>` has a number of events for media loading, playback, and the player itself. Listen to these events using `addEventListener()` or by assigning an event listener to the `oneventname` property of `<mux-player>`.
39
+ Docs and guides live on [docs.mux.com](https://docs.mux.com/guides/video/mux-player?utm_source=github-mux-player).
342
40
 
343
- | Event | Description |
344
- | ---------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
345
- | `abort` | Fired when the resource was not fully loaded, but not as the result of an error. |
346
- | `canplay` | Fired when the user agent can play the media, but estimates that not enough data has been loaded to play the media up to its end without having to stop for further buffering of content. |
347
- | `canplaythrough` | Fired when the user agent can play the media, and estimates that enough data has been loaded to play the media up to its end without having to stop for further buffering of content. |
348
- | `durationchange` | Fired when the duration property has been updated. |
349
- | `emptied` | Fired when the media has become empty; for example, when the media has already been loaded (or partially loaded), and the HTMLMediaElement.load() method is called to reload it. |
350
- | `ended` | Fired when playback stops when end of the media (`<audio>` or `<video>`) is reached or because no further data is available. |
351
- | `error` | Fired when the resource could not be loaded due to an error. |
352
- | `loadeddata` | Fired when the first frame of the media has finished loading. |
353
- | `loadedmetadata` | Fired when the metadata has been loaded. |
354
- | `loadstart` | Fired when the browser has started to load a resource. |
355
- | `pause` | Fired when a request to pause play is handled and the activity has entered its paused state, most commonly occurring when the media's `HTMLMediaElement.pause()` method is called. |
356
- | `play` | Fired when the paused property is changed from true to false, as a result of the `HTMLMediaElement.play()` method, or the `autoplay` attribute. |
357
- | `playing` | Fired when playback is ready to start after having been paused or delayed due to lack of data. |
358
- | `progress` | Fired periodically as the browser loads a resource. |
359
- | `ratechange` | Fired when the playback rate has changed. |
360
- | `resize` | Fired when one or both of the videoWidth and videoHeight properties have just been updated. |
361
- | `seeked` | Fired when a seek operation complete. |
362
- | `seeking` | Fired when a seek operation begin. |
363
- | `stalled` | Fired when the user agent is trying to fetch media data, but data is unexpectedly not forthcoming. |
364
- | `suspend` | Fired when the media data loading has been suspended. |
365
- | `timeupdate` | Fired when the time indicated by the currentTime property has been updated. |
366
- | `volumechange` | Fired when the volume has changed. |
367
- | `waiting` | Fired when playback has stopped because of a temporary lack of data. |
41
+ API reference lives [on Github](./REFERENCE.md).