Github GitHub - BMSVieira/moovie.js: Movie focused HTML5 Player
source link: https://github.com/BMSVieira/moovie.js
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
moovie.js - Movie focused HTML5 Player
Features:
- Fully customizable
- Built-in caption offset adjust on the fly
- Adjust speed on the fly
- Built-in support for
.vtt
and.srt
caption files - Add tracks/captions dynamically
- Standardized events / shortcuts / API
- No dependencies, built with VanillaJS
- Tested in all modern browsers
- Responsive
Coming soon:
- Caption customization
- Remove tracks/captions dynamically
Demo:
https://bmsvieira.github.io/moovie.js/
Installation:
1 - Include JavaScript Source.
<script src="path/to/moovie.js"></script>
2 - Include Styles.
<link rel="stylesheet" href="path/to/moovie.css">
4 - Set HTML.
<video id="example" poster="<<path-to-poster>>"> <source src="<<path-to-file.mp4>>" type="video/mp4"> <track kind="captions" label="Portuguese" srclang="pt" src="<<path-to-caption.vtt>>"> <track kind="captions" label="English" srclang="en" src="<<path-to-caption.vtt>>"> Your browser does not support the video tag. </video>
3 - Initilize.
document.addEventListener("DOMContentLoaded", function() { var demo = new Moovie({ selector: "#example", dimensions: { width: "100%" } }); });
CDN:
You can use our CDN (provided by JSDelivr) for the JavaScript and CSS files.
// Javascript <script src="https://cdn.jsdelivr.net/gh/BMSVieira/moovie.js@latest/js/moovie.min.js"></script> // CSS <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/BMSVieira/moovie.js@latest/css/moovie.min.css">
Captions:
Currently it has full support for WebVTT(.vtt)
and SubRip(.srt)
.
To add a track use the standard html as the example below.
<track kind="captions" label="<<Language>>" srclang="<<SourceLang>>" src="<<path-to-caption.vtt/.srt>>">
Caption Offset Adjust:
It is possible to adjust the offset by a total of 10 seconds
(-5 / +5) on the fly.
Shortcuts:
Key DescriptionSpaceBar
Toggle Play
K
Toggle Play
F
Toggle Fullscreen
→
Forward 5 seconds
←
Backward 5 seconds
M
Toggle Mute
API > Methods:
togglePlay: Play/Pause video
demo.togglePlay();
toggleSubtitles: Enable/Disable subtitles
demo.toggleSubtitles();
toggleFullscreen: Enable/Disable fullscreen
demo.toggleFullscreen();
addTrack: Add multiple/single captions to player
Name Default Descriptionlabel
New Subtitle
Name of the new subtitle in the caption box
srclang
New
Country designation
src
---
Path to the file [Can not be empty]
demo.addTrack({ options : { 0: { label: 'Italian', srclang: "it", src: "<<path-to-file.vtt/.srt" }, 1: { label: 'Spanish', srclang: "es", src: "<<path-to-file.vtt/.srt" } } }
API > Gets:
// Returns player DOM element demo.playerElement // Returns a boolean indicating if the current player is playing. demo.playing // Returns a boolean indicating if the current player is paused. demo.paused // Returns a boolean indicating if the current player is stopped. demo.stopped // Returns a boolean indicating if the current player has finished playback. demo.ended // Returns currentTime of the player. demo.currentTime // Returns the duration for the current media. demo.duration // Returns a boolean indicating if the current player is seeking. demo.seeking // Returns the volume of the player. demo.volume // Returns a boolean indicating if the current player is muted. demo.muted // Returns current playRate demo.speed // Returns mininum speed allowed demo.minimumSpeed // Returns maximum speed allowed demo.maximumSpeed // Returns mininum caption offset allowed demo.minimumOffset // Returns maximum caption offset allowed demo.maximumOffset // Returns current caption offset demo.captionOffset // Returns current source of the player demo.source
API > Sets:
// Set currentTime to given number(seconds) demo.currentTime = 60 // Set player's volume to given number (0.5 is half the volume) demo.volume = 0.5 // Set player's playbackRate to given number (0.1 to 8) demo.speed = 2 // Set player's caption offset to given number (-5 to 5) demo.captionOffset = 2
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK