3.1.0 • Published 3 years ago

@thuoe/mp4-video-player v3.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Player

Installation

$ npm install --save @thuoe/mp4-video-player

Import within a Polymer 3 element

import { PolymerElement, html } from '@polymer/polymer';
import '@thuoe/mp4-video-player';

class SampleElement extends PolymerElement {
  static get template() {
    return html`
      <mp4-video-player></mp4-video-player>
    `;
  }
}
customElements.define('sample-element', SampleElement);

Running Demo

$ npm start

This involves using the Polymer CLI command polymer serve.

First, make sure you have the Polymer CLI and npm (packaged with Node.js) installed. Run npm install to install the element's dependencies. This development server will transpile ES6 code to ES5 using Babel during runtime.

The live demo page will be available to view via http://127.0.0.1:8081/components/@thuoe/mp4-video-player/

Running Tests

$ npm test

Running ESLint

$ npm run lint

Video Player Properties

The following properties below are accessible and writable to use:

PropertyDescriptionTypeDefault Value
titleTitle positioned on top of the video playerStringundefined
srcFile path to .mp4 videoStringundefined
posterFile path to poster image. It can be a relative or absolute URLStringundefined
timelinePreviewDetermines if the timeline preview above the track appears when hoveringBooleanfalse
autoPlayWhether the video should start playing as soon as it is loadedBooleanfalse
loopWhether the video should start over again, every time it is finishedBooleanfalse
volumeThe volume scaled from 0-1Number0.5
timeThe current time in seconds of the video playbackNumber0
skipBySkip ahead or behind (in seconds) the current time based on the right or left arrow keys respectivelyNumber5

Video Player Read-Only Properties

The following properties below are accessible but cannot be altered dynamically:

Read-only propertyDescriptionTypeDefault Value
durationThe total duration of the video file after it has loadedNumber0
playingIf the video is playingBooleanfalse
mutedIf the video is mutedBooleanfalse
endedIf the video has endedBooleanfalse
fullscreenIf the video is in fullscreen modeBooleanfalse

Custom CSS Properties

The following custom CSS variables are also available for custom styling the video player:

Custom propertyDescriptionDefault Value
--video-title-colorColor of the video titlergba(255,255,255,.9)
--video-large-play-button-colorLarge play button color#d32f2f
--video-large-play-button-hover-colorLarge play button hover color#9a0007
--video-track-fill-colorTrack fill color#d32f2f
--video-thumb-colorThumb color used for dragging#fff
--video-control-icons-background-hover-colorControl icons background hover color#d32f2f
---video-time-preview-background-colorTimeline preview background color#d32f2f
--video-menu-background-colorMenu background colorrgba(255,255,255,.9)
--video-menu-item-colorMenu item background colorrgba(255,255,255,.9)
--video-menu-item-icon-colorMenu icon colorblack
--video-menu-item-hover-colorMenu item hover color#d32f2f
--video-menu-item-icon-hover-colorMenu icon hover colorwhite
--video-tooltip-background-colorTooltip background colorrgba(255,255,255,.9)
--video-pulse-icon-colorPulse icon background color#d32f2f
--video-font-familyFont-family used throughout video playerArial, Helvetica, sans-serif

HTML Example:

<!doctype html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, minimum-scale=1, initial-scale=1, user-scalable=yes">
    <title>mp4-video-player demo</title>
    <script type="module">
        import '@webcomponents/webcomponentsjs/webcomponents-loader.js';
        // custom-style element invokes the custom properties polyfill
        import '@polymer/polymer/lib/elements/custom-style.js';
        import '@thuoe/mp4-video-player/mp4-video-player.js'
    </script>
</head>
<body>
    <h3>Video player using custom CSS properties</h3>
    <!-- ensure that custom props are polyfilled on browsers that don't support them -->
    <custom-style>
        <style is="custom-style">
            mp4-video-player {
                /* Set the values for the custom CSS properties */
                --video-thumb-color: red;
                --video-tooltip-background-color: orange;
                --video-menu-item-hover-color: magenta;
            }
        </style>
    </custom-style>
    <mp4-video-player></mp4-video-player>
</body>
</html>

Or you can dynamically change the CSS properties at runtime..

window.addEventListener('WebComponentsReady', () => {
  // when the video player element has finished initializing..
  const player = document.querySelector('mp4-video-player');
  player.updateStyles({
      '--video-min-width': '750px',
      '--video-min-height': '300px',
      '--video-title-color': 'red'
      ...
  });  
});

Keyboard Shortcuts

This video player has intergrated the following shortcuts to further enhance playback experience:

Keyboard ShortcutIntended Action
space or pToggle play
mToggle mute
fToggle fullscreen
Skip ahead
Skip behind
Volume up
Volume down

Custom Events

The player has a suite of events created using the CustomEvent API at your disposal to listen out for:

EventDescriptionevent.detail properties
playWhen the video begins to playcurrentTime
pauseWhen the video has been pausedcurrentTime
endedWhen the video has endedcurrentTime
exitFullscreenWhen exiting fullscreen modecurrentTime
enterFullscreenWhen entering fullscreen modecurrentTime
timeUpdatedWhen the current time has updated to a new positioncurrentTime
volumeChangeWhen the volume has been changedvolume

Code Example:

const videoPlayer = document.querySelector('mp4-video-player');
videoPlayer.addEventListener('timeUpdated', (event) => {
  console.log('Time Updated!', event.detail.currentTime);
});
3.1.0

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago

2.7.0

3 years ago

2.6.1

3 years ago

2.6.0

3 years ago

2.5.0

4 years ago

2.4.0

4 years ago

2.3.1

4 years ago

2.3.0

4 years ago

2.2.0

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.0

4 years ago

1.4.0

4 years ago

1.3.0

4 years ago

1.2.1

4 years ago

1.2.0

4 years ago

1.1.0

4 years ago

1.0.0

4 years ago

0.0.1

4 years ago