Giter Club home page Giter Club logo

x-video's Introduction

x-video

An enhanced video player for modern browsers with a consistent UI and extra features!

Introduction

<x-video> works as a drop-in replacement for the <video> tag. Before:

<video src="video.webm" autoplay loop></video>

After:

<x-video src="video.webm" autoplay loop></x-video>

Everything works like the original video element:

  • <video> tag attributes (controls, autoplay...).
  • The video element attributes (videoWidth, muted...).
  • The video element methods (canPlayType(), pause()...).
  • The video element events (play, pause...).

Working in a no JavaScript environment

If you want to make sure the player will work on browsers with no JavaScript support, just add a <video> tag with the needed attributes inside your <x-video>:

<x-video>
  <video src="video.webm" autoplay loop></video>
</x-video>

x-video will run normally, but will fallback to the native player if JavaScript is not available.

Extra features

Chapter navigation

If you add a chapter track to a video, buttons to navigate to the next/previous chapters are added:

<x-video src="video.webm">
  <track kind="chapters" src="vtt/chapters.vtt" srclang="en" default>
</x-video>

At least one <track> tag must have a kind="chapters" and default attributes with a src pointing to a valid vtt file.

When one of these 2 buttons is clicked, the element fires a chapterchange event.

Note: the web server must support the Range HTTP header to use this feature.

Playlist

To play several videos successively, add multiple <video> tags inside a <x-video> container:

<x-video controls autoplay>
  <video src="video-1.webm"></video>
  <video src="video-2.webm"></video>
  <video src="video-3.webm"></video>
</x-video>

The videos will be played one after another. Only the attributes of the first one will be preserved, the attributes from the subsequent elements will be ignored.

A videochange event is fired when a new element from the playlist is loaded. By default, the new video is only loaded, but not played. To play it, add a autoplay attribute to <x-video> or listen to the videochange event to trigger the playback in JavaScript:

xVideo.addEventListener('videochange', function() {
  this.play();
});

Methods

playByIndex(index)

To play the video located at a certain index in the playlist, you can do:

<x-video>
  <video src="video-1.webm"></video>
  <video src="video-2.webm"></video>
  <video src="video-3.webm"></video>
</x-video>
<script>
var xVideo = document.querySelector('x-video');
xVideo.playByIndex(2); // Play the 3rd video in the list.
</script>

playChapter(index)

Use playChapter() method to play a specific chapter in the current video:

<x-video>
  <video src="video.webm">
    <track kind="chapters" src="vtt/chapters.vtt" srclang="en" default>
  </video>
</x-video>
<script>
var xVideo = document.querySelector('x-video');
xVideo.playChapter(2); // Start playback from the 3rd chapter.
</script>

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.