Skip to content
This repository has been archived by the owner on Feb 24, 2024. It is now read-only.
/ VideoMaster Public archive

A JavaScript tool to let you implement consistent video playback experience across all devices, enabling you to do whole lot of things while video is playing.

License

Notifications You must be signed in to change notification settings

yqlim/VideoMaster

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

25 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Deprecation notice

This is due to the added playsinline attribute of <video> element in iOS devices. Read more about it on WebKit and Apple.

This will still be useful for you to manipulate video playback with JavaScript, such as arrow keys seeking, spacebar play/pause, video loop, etc..

VideoMaster

A cross-platform video playing tool that enables creative interactions with videos.

Browser support

All major browsers equivalent to IE9 and above.

How to use it?

  1. Include the javascript in your <head></head> section of your HTML, before your page-specific javascript.
<script src="videomaster.js"></script>
  1. Be sure to have an element that will contain your video. For example:
<div id="myContainer"></div>
  1. In your javascript, you can create a VideoMaster instance by:
// Compulsory arguments
var container = document.getElementById('myContaienr'); // Or a querySelector string is good too
var videoSrc = '';                                      // Must have a valid video URL

// Optional configurations and their default values
var acceptedConfig = {
    loop: false,                // Loop video onended.
    muted: false,               // If true, video will not have any audio.
    volume: 1,                  // Value ranges from 0 to 1
    objectFit: 'contain',       // Accepted value: 'cover', 'contain'.
    useCanvas: false,           // If true, use canvas element as video for all platform.
    forceCanvasOniOS: true      // If false, iOS devices will use their native video player, which defeats the purpose of this tool.
    resetOnEnded: false,        // Reset video frame to first frame onended.
    trigger: 'click',           // Custom user gesture required to start/pause video.
    canPause: true,             // If false, video cannot be paused.
    shortcut: true,             // If false, keyboard shortcut will be disabled
    seekFactor: 5,              // Indidates the number of seconds the video will rewind/forward from keyboard shortcut
    onEnded: function(){}       // Adds extra onEnded call
}

var myVideo = new VideoMaster(container, videoSrc, acceptedConfig);
  1. Useful methods:

    • myVideo.play(): Plays the video.
    • myVideo.pause(): Pauses the video.
    • myVideo.togglePlay(): Toggle video play/pause.
    • myVideo.goTo(seconds): Change your video currentTime to specified time in seconds.
    • myVideo.addEventListener(): Attach events to it easily.
    • myVideo.removeEventListener(): Remove events from it easily.
    • myVideo.on(): alias to .addEventListener().
    • myVideo.off(): alias to .removeEventListener().
    • myVideo.muted: Get or set your video to muted or not muted. Accepts boolean value only.
    • myVideo.volume: Get or set your video's volume. Value range from 0 to 1.
    • myVideo.currentTime: Get your video's currentTime. Use myVideo.currentTime = seconds to achieve same effect as myVideo.goTo(seconds).
    • myVideo.paused: Check if your video is paused. Returns true if paused.
    • myVideo.duration: Returns your video total duration in seconds.
  2. Keyboard shortcuts:

    • space key: Toggle play/pause.
    • left arrow key: Rewind video to n seconds before.
    • right arrow key: Forward video to n seconds after.

When can I use it?

You can use it when:

  1. You want to prevent videos from automatically go fullscreen (i.e. on iOS devices).
  2. You want to create an interactive video content (that actually requires user-induced gesture, i.e., swipe, tap, shake, etc.).
  3. You want your audiences to be able to keep scrolling the page while video plays.
  4. You want consistent video playing experience across different devices and platforms (i.e., iOS vs Android);

And more.

Future Plans

  1. Add video controls support.

Appreciation

This project is inspired by:

  1. Stanko for CanvasVideoPlayer.js.

About

A JavaScript tool to let you implement consistent video playback experience across all devices, enabling you to do whole lot of things while video is playing.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published