msc-ez-video
Modern browsers already had a vivid player for . 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
That's take a look what can
(There will be only sound and picture in picture functions display when controls not set.)
Features
- Tap
to toggle play / pause. - Double click
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
- Required Script
<script
type="module"
src="https://your-domain/wc-msc-ez-video.js"
script>
- Structure
Put
<msc-ez-video
src="your-video-path.mp4"
poster="your-video-thumbnail-path.jpg"
width="16"
height="9"
muted
autoplay
loop
controls
title="your video title"
artist="your video artist"
>msc-ez-video>
Or
<msc-ez-video>
<script type="application/json">
{
"src": "your-video-path.mp4",
"poster": "your-video-thumbnail-path.jpg",
"width": 16,
"height": 9,
"muted": true,
"autoplay": true,
"loop": true,
"controls": true,
"title": "your video title",
"artist": "your video artist"
}
script>
msc-ez-video>
Otherwise, developers could also choose remoteconfig
to fetch config for
<msc-ez-video
remoteconfig="https://617751a89c328300175f58b7.mockapi.io/api/v1/ezVideo"
...
>msc-ez-video>
JavaScript Instantiation
<script type="module">
import { MscEzVideo } from 'https://your-domain/wc-msc-ez-video.js';
//use DOM api
const nodeA = document.createElement('msc-ez-video');
document.body.appendChild(nodeA);
nodeA.src = 'your-video-path.mp4';
nodeA.poster = 'your-video-thumbnail-path.jpg';
// new instance with Class
const nodeB = new MscEzVideo();
document.body.appendChild(nodeB);
nodeB.src = 'your-video-path.mp4';
nodeB.poster = 'your-video-thumbnail-path.jpg';
// new instance with Class & default config
const config = {
src: 'your-video-path.mp4',
poster: 'your-video-thumbnail-path.jpg',
...
};
const nodeC = new MscEzVideo(config);
document.body.appendChild(nodeC);
script>
Style Customization
<style>
msc-ez-video {
/* slider thumb */
--slider-thumb-with: 14px;
--slider-thumb-color: rgba(255,0,0,1);
/* indicator */
--indicator-background: rgba(255,255,255,.2);
--indicator-buffer-start: rgba(255,255,255,.4);
--indicator-buffer-end: rgba(255,255,255,.4);
--indicator-duration-start: rgba(255,0,0,1);
--indicator-duration-end: rgba(255,0,0,1);
/* time information */
--time-text-size: 16px;
--time-text-color: #fff;
/* warning information */
--warning-font-size: 16px;
--warning-color: #fff;
--warning-text: 'Some errors occured. Please try later.';
/* function button */
--action-height: 36px;
--action-icon-size: auto 65%;
--ico-play: url(ico-play.svg);
--ico-pause: url(ico-pause.svg);
--ico-mute: url(ico-mute.svg);
--ico-unmute: url(ico-unmute.svg);
--ico-fullscreen: url(ico-fullscreen.svg);
--ico-fullscreen-exit: url(ico-fullscreen-exit.svg);
--ico-pip: url(ico-pip.svg);
--ico-replay: url(ico-replay.svg);
--ico-warning: url(ico-warning.svg);
--ico-forward-5: url(ico-forward-5.svg);
--ico-forward-10: url(ico-forward-10.svg);
--ico-backward-5: url(ico-backward-5.svg);
--ico-backward-10: url(ico-backward-10.svg);
--ico-speed-up-rate: url(ico-speed-up-rate.svg);
--ico-speed-down-rate: url(ico-speed-down-rate.svg);
/* reaction */
--reaction-width: 52px;
--reaction-bgc-start: rgba(0,0,0,.4);
--reaction-bgc-end: rgba(0,0,0,.4);
/* tip */
--tip-font-size: 12px;
--tip-line-height: 1.8;
--tip-color: #fff;
--tip-background: rgba(0,0,0,.6);
--tip-play: 'Play';
--tip-pause: 'Pause';
--tip-unmute: 'Unmute';
--tip-mute: 'Mute';
--tip-fullscreen: 'Full screen';
--tip-fullscreen-exit: 'Exit full screen';
--tip-PiP: 'Picture in Picture';
/* playbackRate */
--playbackrate-font-size: 18px;
--playbackrate-line-height: 2;
--playbackrate-color: #fff;
--playbackrate-background: rgba(0,0,0,.6);
}
style>
Attributes
- src
Set
<msc-ez-video
src="your-video-path.mp4"
...
>msc-ez-video>
- poster
Set
<msc-ez-video
poster="your-video-thumbnail-path.mp4"
...
>msc-ez-video>
- width
Set 16
.
<msc-ez-video
width="16"
...
>msc-ez-video>
- height
Set 9
.
<msc-ez-video
height="9"
...
>msc-ez-video>
- title
Set unknown title
".
<msc-ez-video
tile="your-video-title"
...
>msc-ez-video>
- artist
Set unknown artist
".
<msc-ez-video
artist="your-video-artist"
...
>msc-ez-video>
- crossorigin
Set anonymous
".
<msc-ez-video
crossorigin="use-credentials"
...
>msc-ez-video>
- muted
Set false
. Note: If developers like to implement autoplay, muted
must set in mobile.
<msc-ez-video
muted
...
>msc-ez-video>
- autoplay
Set muted
must set in mobile.
<msc-ez-video
autoplay
muted // must set to active autoplay
...
>msc-ez-video>
- loop
Set false
. There will be a replay sign appeared when video fininshed play once loop doesn't set.
<msc-ez-video
loop
...
>msc-ez-video>
- controls
Full function contrl panel will only display in fullscreen mode unless controls set. Default is false
.
<msc-ez-video
controls
...
>msc-ez-video>
Keyboard shortcut
- k
Toggle
- space
Toggle
- m
Toggle
- f
Toggle
- i
Toggle
- esc
Turn off fullscreen mode.
- ←
5
seconds.
- →
5
seconds.
- j
10
seconds.
- l
10
seconds.
- <
Decrease 0.25
.
- >
Increase 2
.
- 0 ~ 9
7
means to timeline 70%
.
Properties
Property Name | Type | Description |
---|---|---|
src | String | Getter / Setter for |
poster | String | Getter / Setter for |
title | String | Getter / Setter for |
artist | String | Getter / Setter for |
width | Number | Getter / Setter for |
height | Number | Getter / Setter for |
crossorigin | String | Getter / Setter for anonymous " or "use-credentials "). |
muted | Boolean | Getter / Setter for |
autoplay | Boolean | Getter / Setter for |
loop | Boolean | Getter / Setter for |
controls | Boolean | Getter / Setter for |
currentTime | Number | Getter / Setter for |
duration | Number | Getter for |
playbackRate | Number | Getter / Setter for 0.25 ~ 2 . |
paused | Boolean | Getter for |
fullscreened | Boolean | Getter for |
PiPed | Boolean | Getter for |
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 |
ez-video-pause | Fired when |
ez-video-seek | Fired when |
ez-video-mutechange | Fired when |
ez-video-fullscreenchange | Fired when |
ez-video-PiPchange | Fired when |
ez-video-ratechange | Fired when |
ez-video-error | Fired when |