EZ Video
Modern browsers already had a vivid player for <video />
. However, web developers and designers still want to custom their own style player for different situations.
Sounds like web component will do a lot favor for this purpose. With <msc-ez-video />
support, customize control panel will become a piece of cake. <msc-ez-video />
adopts CSS custom properties, developers could style them as they want.
That's take a look what can <msc-ez-video />
do in different combination ?
(There will be only sound
and picture in picture
functions display when controls
not set.)
autoplay、muted and loop
muted and loop
muted and control panel
unmuted
unmuted and control panel
Features
- Tap
<msc-ez-video />
to toggle play / pause. - Double click
<msc-ez-video />
to turn on / off fullscreen. - Full function control panel will only display in fullscreen mode unless attribute -
controls
set. - Picture in picture support once browser enable.
- Developers could customize control panel's appearance with CSS custom properties.
Basic Usage
<msc-ez-video />
is a web component. All we need to do is put the required script into your HTML document. Then follow <msc-ez-video />
's html structure and everything will be all set.
Required Script
Structure
Put <msc-ez-video />
into HTML document. It will have different functions and looks with attribute mutation.
Or
Otherwise, developers could also choose remoteconfig
to fetch config for <msc-ez-video />
.
JavaScript Instantiation
<msc-ez-video />
could also use JavaScript to create DOM element. Here comes some examples.
Style Customization
<msc-ez-video />
uses CSS variables to hook control panel's theme. That means developer could easy change it into the looks you like.
Attributes
<msc-ez-video />
supports some attributes to let it become more convenience & useful.
src
Set <msc-ez-video />
's video source.
poster
Set <msc-ez-video />
's poster.
width
Set <msc-ez-video />
's width ratio. Default is 16.
height
Set <msc-ez-video />
's height ratio. Default is 9.
title
Set <msc-ez-video />
's title. Default is "unknown title".
artist
Set <msc-ez-video />
's artist information. Default is "unknown artist".
crossorigin
Set <msc-ez-video />
's crossorigin. Default is "anonymous".
muted
Set <msc-ez-video />
mute active or not. Default is false.
Note: If developers like to implement autoplay, muted must set in mobile.
autoplay
Set <msc-ez-video />
autoplay active or not. Default is false.
Note: If developers like to implement autoplay, muted must set in mobile.
loop
Set <msc-ez-video />
loop active or not. Default is false. There will be a replay sign appeared when video fininshed play once loop doesn't set.
controls
Full function contrl panel will only display in fullscreen mode unless controls set. Default is false.
Keyboard shortcut
<msc-ez-video />
also comes with keyboard shortcut. I believe this will make <msc-ez-video />
more vivid & more useful.
k :
Toggle <msc-ez-video />
play or pause.
space :
Toggle <msc-ez-video />
play or pause.
m :
Toggle <msc-ez-video />
mute or not.
f :
Toggle <msc-ez-video />
into fullscreen or not.
i :
Toggle <msc-ez-video />
into picture in picture or not.
esc :
Turn off fullscreen mode.
← :
<msc-ez-video />
backward 5 seconds.
→ :
<msc-ez-video />
forward 5 seconds.
j :
<msc-ez-video />
backward 10 seconds.
l :
<msc-ez-video />
forward 10 seconds.
< :
Decrease <msc-ez-video />
playback rate. Minimum is 0.25.
> :
Increase <msc-ez-video />
playback rate. Maximum is 2.
0 ~ 9:
<msc-ez-video />
jumps to specific timeline. Ex: 7 means to timeline 70%.
Properties
Property Name | Type | Description |
---|---|---|
src
|
String | Getter / Setter for <msc-ez-video /> 's video source. |
poster
|
String | Getter / Setter for <msc-ez-video /> 's poster. |
title
|
String | Getter / Setter for <msc-ez-video /> 's title. |
artist
|
String | Getter / Setter for <msc-ez-video /> 's artist. |
width
|
Number | Getter / Setter for <msc-ez-video /> 's width ratio. |
height
|
Number | Getter / Setter for <msc-ez-video /> 's height ratio. |
crossorigin
|
String | Getter / Setter for <msc-ez-video /> 's crossorigin. (It might be "anonymous " or "use-credentials ") |
muted
|
Boolean | Getter / Setter for <msc-ez-video /> 's mute status. |
autoplay
|
Boolean | Getter / Setter for <msc-ez-video /> 's autoplay status. |
loop
|
Boolean | Getter / Setter for <msc-ez-video /> 's loop status. |
controls
|
Boolean | Getter / Setter for <msc-ez-video /> 's control panel status. |
currentTime
|
Number | Getter / Setter for <msc-ez-video /> 's currentTime (in seconds). |
duration
|
Number | Getter for <msc-ez-video /> 's duration (in seconds). |
playbackRate
|
Number | Getter / Setter for <msc-ez-video /> 's playback rate. Rate should between 0.25 ~ 2. |
paused
|
Boolean | Getter for <msc-ez-video /> 's pause status. |
fullscreened
|
Boolean | Getter for <msc-ez-video /> 's full screen status. |
PiPed
|
Boolean | Getter for <msc-ez-video /> 's picture in picture status. |
Mathods
Mathod Signature | Description |
---|---|
play
|
Play video. |
pause
|
Pause video |
requestFS
|
Switch into full screen mode. Note: this is high-trusted event. |
exitFS
|
Switch back to normal mode. Note: this is high-trusted event. |
requestPiP
|
Switch into picture in picture mode. Note: this is high-trusted event. |
exitPiP
|
Switch back to normal mode. Note: this is high-trusted event. |
Events
Event Signature | Description |
---|---|
ez-video-play
|
Fired when <msc-ez-video /> played. |
ez-video-pause
|
Fired when <msc-ez-video /> paused. |
ez-video-seek
|
Fired when <msc-ez-video /> seeked. |
ez-video-mutechange
|
Fired when <msc-ez-video /> 's mute status changed. |
ez-video-fullscreenchange
|
Fired when <msc-ez-video /> full screen changed. |
ez-video-PiPchange
|
Fired when <msc-ez-video /> picture in picutre changed. |
ez-video-ratechange
|
Fired when <msc-ez-video /> playback rate changed. |
ez-video-error
|
Fired when <msc-ez-video /> error occured. |