Guides: How to customize Mux Player and make it your own

0:00

Okay, now that we have Mux Player set up, let's

0:02

start customizing the look and feel of the player.

0:06

First things first, uh, we might want to

0:08

customize the poster image.

0:09

The default poster image will be the midpoint of the

0:12

video, which is the default.

0:14

Thumbnail and that's returned from the mux thumbnail API.

0:17

Um, if we want to change that a little bit, we can pass in

0:20

this thumbnail time attribute.

0:22

So let's say I want the thumbnail time from the five

0:25

second mark and do that.

0:28

And that'll be the thumbnail from five seconds or

0:30

let's say I want the 22 seconds thumbnail time.

0:33

Okay.

0:33

and do that.

0:34

Now it'll be the thumbnail from 22 seconds.

0:36

So that's handy when you want a thumb, the poster to be from

0:40

a frame from the video itself.

0:42

Um, if you have a completely unrelated, um, image that you

0:46

want to use for the thumbnail, you can do that as well

0:49

with the poster attributes.

0:50

You can say poster equals, and you can pass in a URL,

0:54

um, pointing to an image and use that as your poster.

0:58

Um, so that's the way to con That's a way to

1:01

customize the thumbnail.

1:03

Next is let's say you have a brand color that you want

1:06

to use and you just want to kind of theme the player

1:08

according to your brand.

1:10

We call that the primary color attributes.

1:12

You can pass in that.

1:14

Um, I have this orange color here I can use, and now

1:18

that'll theme all the controls in that primary color and

1:22

you can see how that works.

1:24

Um, what else can we do here?

1:25

Oh, we can add a video title.

1:27

So, um, pass in here title equals.

1:31

my mux video, um, passing a title that'll show

1:34

up in the top left.

1:36

Um, so that's handy.

1:37

And then the thing about mux player is because it

1:40

is just a plain HTML web component, um, we can

1:43

style this thing with CSS.

1:46

Um, just kind of like you, you would style any HTML element.

1:50

So let's give this some style here and let's give

1:53

this, um, uh, mux player.

1:56

So let's select it and then say with.

2:02

100 percent max with, uh, 500 pixels.

2:08

Let's give it a display block by default.

2:11

It's inline blocks.

2:11

Let's give it a display block and then, um, margin

2:17

40 pixels at the top and auto on the sides.

2:20

So that way it'll be kind of nice and centered.

2:23

My page refresh this.

2:27

Okay, so now you can see it's centered here directly

2:30

in the middle of the page.

2:32

And see, I'm just using normal CSS to style this.

2:37

Now, let's say for my particular video, I don't care

2:39

for some of these controls.

2:41

Let's say I don't want users to have the control

2:43

to adjust the playback rate, for example.

2:47

What I can do here is We have some CSS variables

2:51

for, um, showing for, you know, controlling the

2:55

display value of these.

2:57

Um, first of all, dash dash controls none, that'll just

3:00

hide all of the controls.

3:02

So I do that.

3:06

And now you can see there's no controls here.

3:08

Um, well, that's not exactly what I want.

3:10

So let's say, um, so let's undo that.

3:18

Okay.

3:18

Um, these are the controls available.

3:20

So there's the pip button, which one, Do we want, okay,

3:24

let's say the seek that, uh, the, uh, the rate playback

3:28

rate, where is playback rate, playback rate button.

3:31

None.

3:32

So copy that one.

3:36

Let's do that.

3:37

And let's say I also want to disable the seek

3:39

for seek backward and seek forward buttons.

3:41

Cause maybe I just have a short video here and

3:44

you know, you, my users don't really need to seek.

3:46

I can just hide that.

3:47

You can see the playback rate.

3:48

Control is gone, the forward, backward controls

3:51

are gone, um, but I still have everything else.

3:55

So it's easy to just kind of customize the field with CSS.

3:58

Now if you really want to get into it, um, you can, you can

4:03

hide, you can see that these controls, how they kind of,

4:05

they jump around depending on the size of the container.

4:08

Oh, I have a max 500 pixels.

4:10

Let me increase that.

4:11

Let me make this 1000 pixels.

4:15

Okay.

4:15

So you can see that, uh, you know, sometimes the

4:21

controls are at the top or at the, at the bottom, um,

4:23

depending on the screen size.

4:25

So you can really get granular to control.

4:27

If you only want to hide this control when it's on the

4:30

bottom, but you're okay with it being on the top, then

4:32

you can, you can control that with these CSS variables.

4:34

Mux Player also exposes CSS parts.

4:38

So that we have some documentation here so you

4:40

can really kind of control the CSS of the specific

4:43

parts that are exported and that's kind of a native web

4:46

component kind of pattern that we use to expose pieces

4:50

of the player for styling.

4:52

The control's backdrop color so you can control that.

4:55

That one you have to be a little bit of, you know,

4:56

Careful with because there is a contrast ratio

4:59

requirement for accessibility, so be careful changing

5:01

changing that around.

5:02

You don't want to make it.

5:03

Um, if you get rid of it completely, then the controls

5:06

won't be visible from an accessibility standpoint.

5:08

So primary color and secondary color.

5:10

We talked about that.

5:11

Um, and now when you want to kind of change the

5:15

default behavior, much player pretty much supports

5:18

the attributes that the video element supports.

5:21

So muted, for example, I can pass muted here for the

5:25

player to start off muted.

5:26

Um, you can see it's muted.

5:29

Um, oftentimes people want to autoplay videos.

5:32

So the autoplay attribute, as you can see, it's muted

5:35

and it's autoplaying.

5:36

Um, autoplay can be a little tricky.

5:38

So, um, we actually kind of extended the autoplay

5:41

attribute for the purposes of Mux player, so where you

5:45

can pass in autoplay equals muted to just always autoplay

5:49

the video in a muted state.

5:51

Um, that's often what you need to do because browsers

5:53

will not allow you to autoplay with sound in most cases.

5:58

Um, we also have the autoplay any value.

6:01

Um, and that means that it'll try to autoplay with sound.

6:05

If that fails, then it will fall back to autoplay muted.

6:08

We have that behavior.

6:09

Okay.

6:10

here.

6:10

If you want to loop the video, for example, like let's

6:13

say you have a video that's playing in the background

6:17

of your webpage and it's looping, then you can do

6:20

loop, uh, autoplay muted.

6:23

So now it'll autoplay muted and it'll loop.

6:26

And then let's say if it's just playing in

6:28

the background, maybe you don't want controls.

6:30

So now you can say controls none.

6:34

So now that should give me a player that has no controls.

6:37

And it's just going to auto play muted in the background.

6:41

Uh, sometimes you may want that if you're, you know,

6:43

have like a hero video that takes up the entire top

6:45

section of your video page.

6:48

So that's all the different ways.

6:50

Um, at least some of the ways that you can

6:51

customize let's play.

6:52

Let's make sure this loops.

6:54

At the end,

6:59

you can see it.

7:00

Yeah, start looping.

7:01

We have keyboard shortcuts enabled by default.

7:03

That works when the player or any of the

7:05

controls has focused.

7:06

You can turn that off with no hot keys.

7:08

Then the other thing when it comes to kind of customizing

7:10

Mux Player is that you get the JavaScript events

7:14

and then regular HTML5 video element fires off.

7:17

So, um, let's, let me get rid of this.

7:20

Let me get rid of this.

7:22

Let's kind of go back to the default.

7:25

And I can write some JavaScript here where,

7:29

um, mux player equals document dot query selector.

7:35

Mux Player, Mux Player.

7:40

addEventListener, and, uh, let's just

7:43

go html5 video events.

7:51

Okay, so here are the events that fire for html5 video.

7:55

Play, playing, let's, let's look at the progress event.

7:57

So I can add the progress event, um, and let's just

8:03

log that to see what we get.

8:15

Okay,

8:22

let's make that muted again, so I don't have to hear that.

8:24

Um,

8:29

so you can see that progress event is firing, um, in that

8:33

callback that I registered.

8:34

So now I might want to use that progress event,

8:37

um, to track a user's progress through the

8:40

video and maybe save their progress into my database

8:44

or something like that.

8:45

So all of these events that you get on the HTML5 video

8:48

element, these are all, you know, Baked into Mux Player,

8:50

you'll see the same ones, same ones firing, so you can just

8:53

add event, event listeners.

8:55

Alright, that is some of the basics of

8:58

customizing Mux Player.