GithubHelp home page GithubHelp logo

h5p-video's Introduction

H5P Video

A simple library that displays a video. Useful when users dynamically add videos to other content.

Events

The goal of H5P.Video is to create one single video API for different video players. This means one set of events regardless of the video source you use. Here's a list of the events that H5P.Video instances will be triggering:

Event description
ready Indicates that the user can now call play().
loaded Triggered after the ready event when the video source is loaded.
This may not trigger until after play() is called due to how loading works on difference devices.
This is useful for updating the UI with the duration and similar data.
Similar to the native loadedmetadata but does handle some special cases like the old Android loading issue.
error Triggered whenever something goes wrong.
event.data contains a localized error message that can be displayed in the UI.
stateChange Triggered whenever the state of the video changes. Possible event.data: H5P.Video.ENDED (0), H5P.Video.PLAYING (1), H5P.Video.PAUSED (2), H5P.Video.BUFFERING (3)
playbackRateChange Triggered when the video playback speed changes. This is similar to the native ratechange however it mocks away some IE issues.
captions Triggered when captions become available, i.e. may not be trigger until after play().
event.data contains a list of valid text tracks that the user may choose from.
qualityChange Triggered to confirm that the quality was successfully changed. I.e. choosing a different quality does not guarantee it will play.
Useful for updating the UI with which quality is currently active.

Here's an example of how you can use these events to react when a user interacts with an Interactive Video. You'll want to be adding this third-party script through your H5P plugin's scripts_alter hook.

H5P.jQuery(document).on('ready', function () {
  if (H5P && H5P.instances[0] && H5P.instances[0].libraryInfo.machineName === 'H5P.InteractiveVideo') {
    H5P.instances[0].video.on('stateChange', function (e) {
      switch (e.data) {
        case H5P.Video.BUFFERING:
          console.log('Loading');
          break;

        case H5P.Video.PLAYING:
          console.log('Playing');
          break;

        case H5P.Video.PAUSED:
          console.log('Paused');
          break;

        case H5P.Video.ENDED:
          console.log('Finished');
          break;
      }
    });
  }
});

Changing Video Quality

The following example illustrates how you may change video quality using JS:

if (H5P && H5P.Video) {
  H5P.VideoHtml5.getExternalQuality = function (sources, set) {
    setTimeout(function () {
      set(sources[0].quality.name);
    }, 3000);
  };
}

License

(The MIT License)

Copyright (c) 2012-2019 Joubel AS

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

h5p-video's People

Contributors

icc avatar fnoks avatar otacke avatar falcon-git avatar timothyylim avatar germanvaleroelizondo avatar thomasmars avatar sr258 avatar weblate avatar viragom avatar jnavroski avatar wturunen avatar sabahuddin avatar nadavkav avatar totoromaum avatar dinism avatar andreascerpus avatar sokunthearithmakara avatar sdif-diba avatar maxtetdev avatar jelenamilinovic avatar e-me avatar dnowba avatar xtractorab avatar tajakobsen avatar stephlabaraque avatar miropuhek avatar johanltpt avatar jannesarkela avatar izendegi avatar

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.