npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

videojs-per-source-behaviors

v3.0.1

Published

A Video.js plugin for enhancing a player with behaviors related to changing media sources.

Downloads

28,352

Maintainers

sachin-brightcovesachin-brightcovealexey.kremsaalexey.kremsamelinda.darvasimelinda.darvasijose.luis.sanchezjose.luis.sanchezpedro-cruzpedro-cruzgabor.kiacz.brightcovegabor.kiacz.brightcoveadambertalanbcadambertalanbcmiklospocsaji_bcmiklospocsaji_bcmaraizamaraizaskarukamannaskarukamannaaviel_resnickaviel_resnicknorma.gonzaleznorma.gonzalezjvaldez1jvaldez1fsalazarbcfsalazarbccognatusbgscognatusbgsmbalasubramaniammbalasubramaniamssahssahdgonzalez89dgonzalez89areis10areis10vmnavarrovmnavarroalfredo-reyesalfredo-reyesjterranovajterranovajfloresbcjfloresbcmlopez.bmlopez.bttabrilla-bcttabrilla-bcmsivallsmsivallssstevanussstevanusrwbarber2rwbarber2rwingerrwingerbcc-bfranklinbcc-bfranklinapenigalapatiapenigalapatilmaultsbylmaultsbysravan.pbrsravan.pbrijunaidfijunaidfmgoncalvesmgoncalvesmfregozomfregozoareveloarevelomadhu_gmadhu_ghugocjimhugocjimdaniel_camposdaniel_camposkevin.schickkevin.schickm.morrisonm.morrisonuomaruomarabarstowbcabarstowbcsbarathansbarathankpandiyarajankpandiyarajanimoronesimoroneswalterseymourbcwalterseymourbcddashkevichddashkevichalbertogomezalbertogomezgestrada-brgestrada-bramillerbrightcoveamillerbrightcovelvohralvohramcho-bcmcho-bcawaldronawaldrondawnpackodawnpackoldominguezldominguezbc-srimron-soutterbc-srimron-soutterrsilva_brightcoversilva_brightcovejoeyleshjoeyleshlmelchorx1lmelchorx1juan-sanchezjuan-sanchezeolveraeolveracloewer_bccloewer_bccarredondocarredondobrianhsubrianhsuniklagbrightcoveniklagbrightcovetsraveling_bctsraveling_bcbcbcliffordbcbcliffordbc-acgarciabc-acgarciaadavila1adavila1kreynoldskreynoldsbgs-devopsbgs-devopsalbinjohnsonalbinjohnsonrtezerartezerabcmneilbcmneilrandresfrandresfv.kozlov_bcv.kozlov_bcnagendra_mnagendra_mmichaelmccarthybcmichaelmccarthybcponeill-bcovponeill-bcovmdeltorobcovmdeltorobcovjmohneycovejmohneycoveinbc01inbc01aperezbrightcoveaperezbrightcoveireyes94ireyes94brightcove-adminbrightcove-admintedktedkabradley-brightcoveabradley-brightcovebc-alivebc-alivelasanchezclasanchezcmarguinbcmarguinbcbrightcove-userbrightcove-userkmasonkmasoncbarstowcbarstowhikehhikehmyerramallamyerramallapdiaspdiasjwhisenantjwhisenantebertaudebertauddsalnikovdsalnikovsharanya.muruganandamsharanya.muruganandamxgarcia_npmxgarcia_npmjguerrajguerrarjunerjunejonbwalshjonbwalshkhaiphamkhaiphamwswanbeckwswanbeckgastafurovgastafurovadalwaniadalwaniekelson-bcoveekelson-bcovesysengsysengmcarreiromcarreirohwoodburyhwoodburyjblakerjblakerbcmauleonbcmauleonpaco_oblea_bcpaco_oblea_bcjsepulvedajsepulvedabiswaranjanbiswaranjanbarroyobarroyobmartinezbmartinezbc-jcarlsonbc-jcarlsoneledezmaeledezmajcuetojcuetoerodrigueserodriguespsousapsousamarcogaraymarcogarayjavibrightjavibrightbcpsalasbcpsalasetobinetobinackbabeackbabecvillasenorcvillasenoromartinezomartinezmgonzalez_bcmgonzalez_bcpdohertybcovpdohertybcovmuthukumar.bcmuthukumar.bcbzizmondbzizmondjmpmacedojmpmacedoscorreiascorreialescorciolescorciocavieiracavieiraarunjeyaprasadarunjeyaprasadbvilvanathanbvilvanathananand.gangadharananand.gangadharanrociosantosrociosantosagarciabcovagarciabcovattinderattinderlauralopezlauralopezskumar85skumar85hrodriguez2hrodriguez2jasilvaantoniojasilvaantoniopalvarezbcpalvarezbcericramosericramoscarlosabajocarlosabajoingrid.s.cruzingrid.s.cruzluis_fernando_lopez_ruizluis_fernando_lopez_ruizvishal64vishal64tresa.bajitresa.bajiluis.garcia.brightcoveluis.garcia.brightcoverodrigofdzrodrigofdzpgutierrezgilpgutierrezgilharish17harish17jjeyaprakashjjeyaprakashrrajendran1698rrajendran1698jlomelijlomelisjimenezsjimenezrwenger_brightcoverwenger_brightcoverujordanrujordanstuartmhstuartmhjherrerabcovjherrerabcovmshiwalmshiwalptamizhptamizhakamalakkannanakamalakkannanroman-bcroman-bctnwannatnwannabsahlas.npmbsahlas.npmdherrera1109dherrera1109hswaminathanhswaminathanechengbcechengbcsbarrettbcsbarrettbcmisteroneillmisteroneillgkatsevgkatsevbrandonocaseybrandonocasey

Readme

videojs-per-source-behaviors

Build Status Greenkeeper badge Slack Status

NPM

A video.js plugin for enhancing a player with behaviors related to changing media sources.

Maintenance Status: Stable

Why?

Detecting when the media source of a player has changed or is about to change is an inexact operation because the resource selection algorithm is asynchronous.

For the most part, Video.js users will be familiar with using the Player#src() method to change the source of the player. One might wonder why we don't simply trigger an event from that function to signal that the source is going to change.

The problem with that is that src() is not the only way to change the source. The underlying <video> element has multiple methods of changing the source as well and we aim to support those here.

This plugin provides events and other tools that aim to make that uncertainty a little less daunting.

Installation

npm install --save videojs-per-source-behaviors

The npm installation is preferred, but Bower works, too.

bower install  --save videojs-per-source-behaviors

Usage

To include videojs-per-source-behaviors on your website or web application, use any of the following methods.

<script> Tag

This is the simplest case. Get the script in whatever way you prefer and include the plugin after you include video.js, so that the videojs global is available.

<script src="//path/to/video.min.js"></script>
<script src="//path/to/videojs-per-source-behaviors.min.js"></script>
<script>
  var player = videojs('my-video');

  player.perSourceBehaviors();
</script>

Browserify

When using with Browserify, install videojs-per-source-behaviors via npm and require the plugin as you would any other module.

var videojs = require('video.js');

// The actual plugin function is exported by this module, but it is also
// attached to the `Player.prototype`; so, there is no need to assign it
// to a variable.
require('videojs-per-source-behaviors');

var player = videojs('my-video');

player.perSourceBehaviors();

RequireJS/AMD

When using with RequireJS (or another AMD library), get the script in whatever way you prefer and require the plugin as you normally would:

require(['video.js', 'videojs-per-source-behaviors'], function(videojs) {
  var player = videojs('my-video');

  player.perSourceBehaviors();
});

API

Once the plugin is invoked on a player - by calling player.perSourceBehaviors() - it begins firing a new event, gains two new methods, and replaces perSourceBehaviors with an object.

sourceunstable Event

The sourceunstable event will be fired when the plugin detects a condition that suggests the video player is in the process of changing sources, but that it's too early to know what the new source is or will be.

This is not a guarantee that the source will even change, but it's close - and one of the goals of this project is to continually improve this detection.

sourcechanged Event

The sourcechanged event will be fired once the call stack is cleared after the first of a subset of standard HTMLMediaElement events is encountered where the currentSrc() returned by the player has changed from the previously cached value.

| previous src | current src | ad state | triggered? | |:------------:|:-----------:|:--------:|:----------:| | null | null | :x: | :x: | | null | foo.mp4 | :x: | :white_check_mark: | | null | ad.mp4 | :white_check_mark: | :x: | | foo.mp4 | foo.mp4 | :x: | :x: | | foo.mp4 | foo.mp4 | :white_check_mark: | :x: | | foo.mp4 | bar.mp4 | :x: | :white_check_mark: | | foo.mp4 | bar.mp4 | :white_check_mark: | :x: | | foo.mp4 | ad.mp4 | :white_check_mark: | :x: | | ad.mp4 | foo.mp4 | :white_check_mark: | :x: |

Extra Event Data

An object with the following properties is passed along with sourcechanged events as the second argument to any listeners:

  • from: The source URL before the event.
  • to: The source URL after the event (and currently).
  • interimEvents: An array of all the events that occurred in the player between the event that triggered the check to the last event that fired before the call stack cleared.

Put another way, the object follows the following schema:

{
  from: <String>,
  to: <String>,
  interimEvents: [{
    time: <Number>,
    event: <Event>
  }, ...]
}

player.onPerSrc()

The onPerSrc() method has the same behavior as on() with the crucial exception that it will unbind itself if the listener is ever called with a different source than when it was bound.

Additionally, these listeners will be removed immediately before the plugin triggers a sourcechanged event. This is done because one of the core use-cases is adding new per-source listeners on the sourcechanged event and there is a chance they can double-up otherwise.

player.onePerSrc()

The onePerSrc() method has the same behavior as onPerSrc() except that it can only be called once.

player.perSourceBehaviors.disable()/player.perSourceBehaviors.enable()

These methods will disable and enable (respectively) the per-source behaviors on this player.

This is useful in more complex use-cases where you might want to manipulate the player state without triggering per-source behaviors. A good example of this might be advertising playback.

What happens when per-source behaviors are disabled?

  • The sourcechanged event will not be fired even if the source changes.
  • Any onPerSrc()/onePerSrc() listeners will not be called.
  • Binding new onPerSrc()/onePerSrc() listeners will be prevented.

player.perSourceBehaviors.disabled()/player.perSourceBehaviors.enabled()

Use these methods to inspect the current enabled/disabled state of the player as pertains to per-source behaviors. Both return a Boolean.

player.perSourceBehaviors.VERSION

Exposes the semantic version number of the plugin. This is also exposed on the plugin function (i.e. videojs.getComponent('Player').prototype.perSourceBehaviors).

License

Apache-2.0. Copyright (c) Brightcove, Inc.