Moovie

Media player made for movies

README



Demo ▪️ Installation ▪️ Shortcuts ▪️ API ▪️ Integrations ▪️ Events
Styling ▪️ Plugins
▪️ Custom Events ▪️ i18n ▪️ Settings



◼️ Features:
-
- 🔧 Fully customizable and Easy-to-use
- 💎 Built-in caption offset adjust on the fly
- 🎬 Built-in support for .vtt and .srt caption files
- 🕹 Built-in Plugins, use the code that you really need!
- 🎯 Built-in CustomEvents, add multiple events that will run a specific currentTime
- 🖊 Add tracks/captions dynamically using our API
- 🗃 Add tracks/captions locally on the fly (no server or upload required)
- 🌠 Adjust speed on the fly
- 🛠 Standardized events / shortcuts / API
- 🖌 Caption customization
- 💪 No dependencies, built with VanillaJS
- 🌎 Tested in all modern browsers
- 💻 Responsive
- 🗃 Integration with webtorrent.js, dash.js, Shaka Player and hls.js
- 🌎 Internationalization (i18n) of controls

◼️ Demo:
-
https://mooviejs.com/

◼️ Installation (Browser):
-

1 - Include JavaScript Source.
  1. ``` js
  2. <script src="path/to/moovie.js"></script>
  3. ```
2 - Include Styles.
  1. ``` js
  2. <link rel="stylesheet" href="path/to/moovie.css">
  3. ```
3 - Set HTML.
  1. ``` html
  2. <video id="example" poster="<<path-to-poster>"
  3.   <source src="<<path-to-file.mp4>" type="video/mp4"
  4.   <track kind="captions" label="Portuguese" srclang="pt" src="<<path-to-caption.vtt>"
  5.   <track kind="captions" label="English" srclang="en" src="<<path-to-caption.vtt>"
  6.   Your browser does not support the video tag.
  7. </video>
  8. ```
4 - Initilize.
  1. ``` js
  2. document.addEventListener("DOMContentLoaded", function() {
  3.    var demo = new Moovie({
  4.      selector: "#example",
  5.      dimensions: {
  6.           width: "100%"
  7.      }
  8.    });
  9. });
  10. ```
Note: Do not forget to include "icons" folder.

◼️ Installation (NPM):
-
1 - Install npm package
  1. ``` js
  2. npm i mooviejs
  3. ```
2 - Include Styles.
  1. ``` js
  2. <link rel="stylesheet" href="path/to/moovie.css">
  3. ```
3 - Set HTML.
  1. ``` html
  2. <video id="example" poster="<<path-to-poster>"
  3.   <source src="<<path-to-file.mp4>" type="video/mp4"
  4.   <track kind="captions" label="Portuguese" srclang="pt" src="<<path-to-caption.vtt>"
  5.   <track kind="captions" label="English" srclang="en" src="<<path-to-caption.vtt>"
  6.   Your browser does not support the video tag.
  7. </video>
  8. ```
4 - Initilize.
  1. ``` js
  2. const Moovie = require('mooviejs');
  3. var demo = new Moovie({
  4.      selector: "#example",
  5.      dimensions: {
  6.           width: "100%"
  7.      },
  8.      icons: {
  9.         path: "<path/to/icons/folder>"
  10.      }
  11. });
  12. ```

◼️ CDN:
-
You can use our CDN (provided by JSDelivr) for the JavaScript and CSS files.

  1. ``` html
  2. // Javascript
  3. <script src="https://cdn.jsdelivr.net/gh/BMSVieira/moovie.js@latest/js/moovie.min.js"></script>
  4. // CSS
  5. <link rel="stylesheet" href="https://cdn.jsdelivr.net/gh/BMSVieira/moovie.js@latest/css/moovie.min.css">
  6. ```

◼️ Captions:
-
Currently it has full support for WebVTT(.vtt) and SubRip(.srt).

▪️ Dynamically (Public server required)

Use the standard html as the example below (source must be in a public server with cross-origin headers).

  1. ``` html
  2. <video>
  3.   <track kind="captions" label="<<Language>" srclang="<SourceLang>" src="<path-to-caption.vtt/.srt>"
  4. </video
  5. ```

▪️ Locally (No server or upload required)

Since browsers won't let you display subtitles loaded locally, you can use moovie's built-in feature that allows you to add local subtitles without a server or any kind of upload.

When loading caption files locally, be sure to save the file with UTF-8 encoding, otherwise you will encounter some decryption errors like "�"

  1. ``` html
  2. Video Player ➔ ⚙️ ➔ Captions ➔ Load Locally
  3. ```
⚠️ This method DOES NOT load anything into server/folder/directory.

◼️ Caption Offset Adjust:
-

It is possible to adjust the offset by a total of `10 seconds` (-5 / +5) on the fly.


◼️ Shortcuts:
-

A player will bind the following keyboard shortcuts when it has focus.

KeyDescription
------
`SpaceBar`Toggle
`K`Toggle
`F`Toggle
`C`Toggle
`M`Toggle
`ArrowRight`Forward
`ArrowLeft`Backward
`Shift`+`W`|
`Shift`+`S`|

◼️ API > Methods:
-

togglePlay:
Play/Pause video

  1. ``` js
  2. demo.togglePlay();
  3. ```

toggleSubtitles:
Enable/Disable subtitles

  1. ``` js
  2. demo.toggleSubtitles();
  3. ```

toggleFullscreen:
Enable/Disable fullscreen

  1. ``` js
  2. demo.toggleFullscreen();
  3. ```

destroy:
Remove current player and unbinds all its events

  1. ``` js
  2. demo.destroy();
  3. ```

build:
Build a new player

  1. ``` js
  2. demo.build();
  3. ```

addTrack:
Add multiple/single captions to player

NameTypeDefaultDescription
------|------
`label``string``NewName
`srclang``string``New`Country
`src``string``---`Path

  1. ``` js
  2. demo.addTrack({
  3.   options : {
  4.         0: {
  5.             label: 'Italian',
  6.             srclang: "it",
  7.             src: "<<path-to-file.vtt/.srt"
  8.         },
  9.         1: {
  10.             label: 'Spanish',
  11.             srclang: "es",
  12.             src: "<<path-to-file.vtt/.srt"
  13.         }
  14.     },
  15.     onComplete: function(){
  16.       console.log("Completed!");
  17.     }
  18. });
  19. ```

change:
Apply changes to current player.

NameTypeDescription
---------
`video``string`New
`video``string`New
`captions``boolean`Remove

  1. ``` js
  2. demo.change({
  3.      video: {
  4.          videoSrc: "<<path-to-video>>",
  5.          posterSrc: "<<path-to-poster>>"
  6.      },
  7.      captions:{
  8.          clearCaptions: true
  9.      },
  10.     onComplete: function(){
  11.       console.log("Completed!");
  12.     }
  13. });
  14. ```

◼️ API > Gets:
-
  1. ``` js
  2. // Returns player DOM element
  3. demo.playerElement

  4. // Returns a boolean indicating if the current player is playing.
  5. demo.playing

  6. // Returns a boolean indicating if the current player is paused.
  7. demo.paused

  8. // Returns a boolean indicating if the current player is stopped.
  9. demo.stopped  

  10. // Returns a boolean indicating if the current player has finished playback.
  11. demo.ended    

  12. // Returns currentTime of the player.
  13. demo.currentTime

  14. // Returns the duration for the current media.
  15. demo.duration

  16. // Returns a boolean indicating if the current player is seeking.
  17. demo.seeking

  18. // Returns the volume of the player.
  19. demo.volume

  20. // Returns a boolean indicating if the current player is muted.
  21. demo.muted

  22. // Returns current playRate
  23. demo.speed

  24. // Returns mininum speed allowed
  25. demo.minimumSpeed

  26. // Returns maximum speed allowed
  27. demo.maximumSpeed

  28. // Returns mininum caption offset allowed
  29. demo.minimumOffset

  30. // Returns maximum caption offset allowed
  31. demo.maximumOffset

  32. // Returns current caption offset
  33. demo.captionOffset

  34. // Returns current source of the player
  35. demo.source
  36. ```

◼️ API > Sets:
-
  1. ``` js
  2. // Set currentTime to given number(seconds)
  3. demo.currentTime = 60

  4. // Set player's volume to given number (0.5 is half the volume)
  5. demo.volume = 0.5

  6. // Set player's playbackRate to given number (0.1 to 8)
  7. demo.speed = 2

  8. // Set player's caption offset to given number (-5 to 5)
  9. demo.captionOffset = 2

  10. // Mute or Unmute player (boolean)
  11. demo.muted = true
  12. ```

◼️ Integrations:
-
|  | Name & Info | Example |
| :-:  | :-: | --- |
|| `WebTorrent`
For more info read WebTorrent documentation.
| [Codepen](https://codepen.io/BMSVieira/pen/vYgpvJX)||| `dash.js`
For more info read dash.js documentation. | [Codepen](https://codepen.io/BMSVieira/pen/BapJqBV)||| `Shaka Player`
For more info read Shaka Player documentation. | [Codepen](https://codepen.io/BMSVieira/pen/PoWEVwe)||| `hls.js`
For more info read hls.js documentation. | [Codepen](https://codepen.io/BMSVieira/pen/ExZorLW)|

◼️ Events:
-

Using Standard Media Events you can listen for events on the target element you setup. check the example below:

  1. ``` js
  2. demo.video.addEventListener("canplay", (event) => {
  3.    console.log(event);
  4. });
  5. ```

EventDescription
------
`abort`|
`canplay`|
`canplaythrough`|
`durationchange`|
`emptied`|
`error`|
`interruptbegin`|
`interruptend`|
`loadeddata`|
`loadedmetadata`|
`loadstart`|
`pause`|
`play`|
`playing`|
`progress`|
`ratechange`|
`seeked`|
`seeking`|
`stalled`|
`suspend`|
`timeupdate`|
`volumechange`|
`waiting`|
`captionchange`Sent
`offsetchange`|
`togglecaption`|

◼️ Styling > Colors:
-

Using CSS Custom Properties you can easily customize your own player.
Check below a list of variables and what they are used for:

NameDescriptionDefault
---------
`--moovie_main_color`Moovie
`--moovie_bg_controls`Background`rgba(16,
`--moovie_bg_submenu`Submenu
`--moovie_bg_cuetimer`Cuetimer
`--moovie_submenu_options_fcolor`|
`--moovie_topic_submenu_fcolor`Submenu
`--moovie_currenttime_color`CurrentTime`white`|
`--moovie_submenu_options_fsize`Submenu`10pt`|
`--moovie_topic_submenu_fsize`Submenu`9pt`|
`--moovie_currenttime_fsize`|`11pt`|
`--moovie_cuetimer_fsize`|`9pt`|
`--moovie_svgicons_width`Icons`15px`|
`--moovie_padding_controls`|`13px`|
`--moovie_caption_fcolor`|`white`|
`--moovie_cuetimer_fcolor`|`white`|

◼️ Styling > Icons:
-
moovie uses .svg icons that are stored in the icons folder that is located by default in the root, however, you can specify a new location in the config options.

  1. ``` js
  2. config: {
  3.     icons: {
  4.         path: "./path/to/folder/"
  5.     }
  6. }
  7. ```
Folder structure:
  1. ``` html
  2. moovie/
  3. ├── icons/
  4. │   ├── back.svg
  5. │   ├── caption.svg
  6. │   ├── cc.svg
  7. │   ├── cog.svg
  8. │   ├── fullscreen.svg
  9. │   ├── mute.svg
  10. │   ├── next.svg
  11. │   ├── pause.svg
  12. │   ├── play.svg
  13. │   ├── volume.svg
  14. |
  15. ├── css/
  16. │   ├── moovie.css
  17. |
  18. ├── js/
  19. │   ├── moovie.js
  20. ```

◼️ Plugins:
-
There are external plugins you can use to add extra features.

to call a plugin, follow the example below:

  1. ``` html
  2. <script src="path/to/plugin.js"></script>
  3. ```
by default, plugins are located in the `./js/plugins/` folder, but you can specify a new location.

  1. ``` js
  2. // Initialize Moovie
  3. var demo = new Moovie({selector: "#example"});

  4. // Call External Plugin (Playlist example)
  5. var PlaylistPlugin = new _Moovie_Playlist({reference: demo});
  6. ```

List of available plugins:

NameDescription|
---------
`_Moovie_Playlist`Create[More

◼️ Custom Events:
-
You can add multiple events that will run at a specific currentTime, for example:

  1. ``` js
  2. var demo = new Moovie({
  3.   selector: "#example",
  4.   customEvents: [
  5.     {
  6.       type: "skip",
  7.       to: "56",
  8.       starttime: "10",
  9.       endtime: "20",
  10.       content: "Skip Intro",
  11.       position: "bottom-left",
  12.       class: "my_class"
  13.     },
  14.     {
  15.     ...
  16.     }
  17.   ]
  18. });
  19. ```

OptionParametersDescription
---------
`type``skip`,Type
`to``int`,Parameters
`starttime``int`|
`endtime``int`|
`content``string`|
`position``top-left`,Button's
`class``string`Custom

◼️ i18n Support:
-
You can translate the player to any language you want in the configurations.

  1. ``` js
  2. config: {
  3.     i18n : {
  4.           play : "(Play:Pause)",
  5.           mute : "(Mute:Unmute)",
  6.           subtitles : "(Enable:Disable) Subtitles",
  7.           ...
  8.       }
  9. }
  10. ```

How translation works is very simple, all text between brackets are the "changing" parts of the string, and in the left side of the ":" is the default state string.

  1. ``` js
  2. ([DEFAULT STATE]:[AFTER ACTION STATE]) [CONTINUES STRING]
  3. ```
Working examples:

  1. ``` js
  2. // English
  3. subtitles : "(Enable:Disable) Subtitles",
  4. // Portuguese
  5. subtitles : "(Ativar:Desativar) Legendas",
  6. // French
  7. subtitles: "(Activer:Désactiver) Les sous-titres"
  8. ```

OptionDefaultDescription
---:-:---
`play``(Play:Pause)`Play
`mute``(Mutar:Desmutar)`Mute
`subtitles``(Enable:Disable)Subtitles
`config``Settings`Settings
`fullscreen``(Enter:Exit)Fullscreen
`main_topic``settings:`Submenu's
`main_caption``Captions`Submenu's
`main_offset``CaptionSubmenu's
`main_speed``Speed`|Submenu's
`main_disabled``Disabled`Submenu's
`main_default``Default`Submenu's
`caption_topic``Captions:`Caption's
`caption_back``Back`Caption's
`caption_load``LoadCaption's
`offset_topic``AdjustOffset's
`speed_topic``SpeedSpeed's

◼️ Settings:
-
OptionTypeDescription
---------
`selector``String`Specify
◼️|
`width``string`Width
◼️|
`captionOffset`|Indicates
`playrateSpeed`|Indicates
`captionSize`|Indicates
◼️|
`playtime`|Indicates
`mute`|Indicates
`volume`|Indicates
`subtitles`|Indicates
`config`|Indicates
`fullscreen`|Indicates
`submenuCaptions`|Indicates
`submenuOffset`|Indicates
`submenuSpeed`|Indicates
`allowLocalSubtitles`|Indicates
◼️|
`path`|Specify

Full Example:

  1. ``` js
  2. document.addEventListener("DOMContentLoaded", function() {
  3.   var demo = new Moovie({
  4.     selector: "#example",
  5.     dimensions: {
  6.          width: "100%"
  7.     },
  8.     config: {
  9.         storage: {
  10.            captionOffset: false,
  11.            playrateSpeed: false,
  12.            captionSize: false
  13.         },
  14.         controls : {
  15.             playtime : true,
  16.             mute : true,
  17.             volume : true,
  18.             subtitles : true,
  19.             config : true,
  20.             fullscreen : true,
  21.             submenuCaptions : true,
  22.             submenuOffset : true,
  23.             submenuSpeed : true,
  24.             allowLocalSubtitles : true  
  25.         },
  26.         i18n : {
  27.             play : "(Play:Pause)",
  28.             mute : "(Mute:Unmute)",
  29.             subtitles : "(Enable:Disable) Subtitles",
  30.             config : "Settings",
  31.             fullscreen : "(Enter:Exit) Fullscreen",
  32.             main_topic: "settings:",
  33.             main_caption: "Captions",
  34.             main_offset: "Caption Offset",
  35.             main_speed: "Speed",
  36.             main_disabled: "Disabled",
  37.             main_default: "Default",
  38.             caption_topic: "Captions:",
  39.             caption_back: "Back",
  40.             caption_load: "Load Locally",
  41.             offset_topic: "Adjust Caption Offset",
  42.             speed_topic: "Speed Adjust"
  43.          }
  44.     },
  45.     icons: {
  46.         path: "./path/to/folder/"
  47.     }
  48.   });
  49. });
  50. ```

◼️ Sponsors:
-

Thanks to JetBrains for supporting this project with its incredible tools!