GithubHelp home page GithubHelp logo

phhu / videojs-abloop Goto Github PK

View Code? Open in Web Editor NEW
41.0 6.0 12.0 28.95 MB

A video.js plugin for looping of a section of video, with GUI and API controls

Home Page: https://unpkg.com/videojs-abloop/sample/basic.html

License: MIT License

JavaScript 98.25% HTML 1.75%
loop video videojs-plugin

videojs-abloop's Introduction

This is a plugin for video.js (http://videojs.com/)

It provides an A/B loop function, allowing a section of a video to be looped over repeatedly.

The settings can be changed dynamically, either programmatically or via a user interface.

Example

See https://unpkg.com/videojs-abloop/sample/basic.html

<html>
	<head>
		<script src="https://vjs.zencdn.net/5.6.0/video.js"></script>
		<link href="https://vjs.zencdn.net/5.6.0/video-js.css" rel="stylesheet" /> 
		<script src="https://unpkg.com/videojs-abloop/dist/videojs-abloop.min.js"></script>		
	</head>
	<body>
		<video id="vid" controls class="video-js"  >
			<source src="https://vjs.zencdn.net/v/oceans.mp4" type='video/mp4'>
		</video>	
		<script>	
			var video = videojs("vid",{
				plugins: {
					abLoopPlugin: {}
				}
			});
			video.ready(function(){
				this.abLoopPlugin.setStart(10).setEnd(15).playLoop();
			});
		</script>
	</body>
</html>

Example from node:

npm install video.js videojs-abloop
//import videojs from 'video.js'
//import abLoopPlugin from 'videojs-abloop'

const videojs = require('video.js');
const abLoopPlugin = require('videojs-abloop');

abLoopPlugin(window,videojs);

const player = videojs('vid',{     //vid is the video element id
  plugins: {
    abLoopPlugin: {
      'start':3
    }
  }
});
player.abLoopPlugin.setEnd(6.5).playLoop();

Interface

GUI

Buttons are created on the right hand side of the control bar to set start and end times for the loop, and to enable and disable looping.

GUI screeshot

  • Start and end buttons (3rd and 2nd from right, showing times):

    • Left click: set start/end time to current video position.
    • Right click: skip the video to start/end position.
    • Shift + left / right click: move start / end position back / forward (by 0.5s)
    • Ctrl + left / right click: move start / end position back / forward (by 0.05s)
  • Loop button (rightmost button):

    • Left click: enable / disable looping.
    • right click: cycle settings for pausing automatically before or after looping.
    • Shift + left/right click: set/extract URL fragment for current loop settings
    • Ctrl + left/right click: set/extract full URL for video with current loop settings
    • Alt + left/right click: set/extract relative URL for video with current loop settings

You can set the buttons not to create using the createButtons setup option.

API

The plugin is controlled by an internal opts object that looks something like this.

{
	"start":0,
	"end":10,
	"enabled":false,
	"loopIfBeforeStart":true,
	"loopIfAfterEnd":true,
	"pauseBeforeLooping":false,
	"pauseAfterLooping":false
}

These can be set on plugin setup or dynamically via API commands.

Assuming video references a videojs player instance:

  • Look at video.abLoopPlugin for functions to call to control the loop.
  • The API methods can be chained together like this: video.abLoopPlugin.setStart().setEnd(8).goToStart().enable();
  • setStart and setEnd will set the start and end positions to the current video position if called with no parameter.
  • Options can be set with video.abLoopPlugin.setOptions({'optionname':value})
  • Options can be read with video.abLoopPlugin.getOptions() or to return some options video.abLoopPlugin.getOptions(["start","end"]).
    • You could save settings by writing this as JSON or whatever (see in samples folder for a crude example).
  • An onLoop callback can be set at video.abLoopPlugin.onLoopCallBack or in the setup options (see example below).
  • An onOptionsChange callback can be set at video.abLoopPlugin.onOptionsChange or in the setup options. This is useful if you implement your own interface.
  • You can also get and apply URL fragments to represent the looping section. E.g. #t=10,15.

API commands

API command notes example
setOptions(optionsObject) Options not specified will not be set setOptions({"start":40,"end":45"})
getOptions(ArrayOfOptionNames?) Call without an argument to get them all. getOptions(["start","end"])
goToStart() set player currentTime to start time
goToEnd()
setStart(startTime?) Call startTime() to set the startTime to the player's currentTime startTime() startTime(30) startTime("0:34:23")
setEnd(endTime?) Call endTime() to set the startTime to the player's currentTime
adjustStart(adjustmentInSec) adjustStart("1m30s") or adjustStart("1:20:30") also work adjustStart(-5)
adjustEnd(adjustmentInSec)
enable() enable the plugin.
disable()
toggle() change enabled status
togglePauseAfterLooping()
togglePauseBeforeLooping()
cyclePauseOnLooping() cycle between four different compinations of settings for pausing on looping
validateOptions() set options to valid values if they are not already. This is called every time the loop condition is checked anyway, but you might want to use it manually if setting options while the player is paused or the plugin disabled
resetToInitialOptions() reset options to the ones provided on setup
playLoop() for convenience, plays the loop from its start. Equivalent to abLoopPlugin.validateOptions().goToStart().enable().player.play()
player reference to parent player object. e.g. video.abLoopPlugin.enable().player.play()
version version number
getAbsoluteUrl() gets the full URL of the loop - e.g. http://domain.com/path/to/video.mp4#t=12,13
getUrl() gets the URL of the loop - e.g. path/to/video.mp4#t=12,13
getUrlFragment() gets the loop URL fragment - e.g. #t=12,13
applyUrl(url) Set the video source and apply loop start and end as per the t=start,end fragment applyUrl('http://path/to/video.mp4#t=12,13')
applyUrlFragment(urlFragment) As above, but only sets the loop start and end from the URL hash fragment applyUrlFragment('#t=12,13') applyUrlFragment('http://path/ignored.mp4#t=12,13')
loopRequired() returns true or false depending on whether the loop would be activated in the current state.

Keyboard

You could use the existing hotkeys plugin to make keyboard controls. See the samples directory for an example.

Sample usage

See the samples folder for working examples.

Include the script:

<script src="videojs-abloop.js"></script>

Alternatively source it from unpkg.com:

<script src="https://unpkg.com/videojs-abloop/dist/videojs-abloop.min.js">

Or use in node.js:

npm install video.js videojs-abloop

import videojs from 'video.js'    
import abLoopPlugin from 'videojs-abloop'

abLoopPlugin(window,videojs);

You initialise the plugin with defaults, and then can set properties at runtime.

//initialise the video with the plugin and initial settings
var video = videojs("videoid",{
	plugins: {
		abLoopPlugin: {
			start:50    	//in seconds - defaults to 0
			,end:55    	//in seconds. Set to  false to loop to end of video. Defaults to false
			,enabled:false			//defaults to false
			,loopIfBeforeStart:false //allow video to play normally before the loop section? defaults to true
			,loopIfAfterEnd:true	// defaults to true
			,pauseAfterLooping: false     	//if true, after looping video will pause. Defaults to false
			,pauseBeforeLooping: false     	//if true, before looping video will pause. Defaults to false
			,createButtons: true		//defaults to true
		}
	}
});

video.play();

setTimeout(function() { 
	console.log("setting new start and end...");
	video.abLoopPlugin.setStart().setEnd(8).enable();
} , 2000);

video.abLoopPlugin.onLoopCallBack = function(api,player){
	var opts = api.getOptions();
	console.log("Looping back to %s sec on %s",opts.start, player.currentSrc() );
	api.setOptions({'pauseAfterLooping': true}); 
	api.setStart(5);
	api.setEnd(15);
};

videojs-abloop's People

Contributors

dependabot[bot] avatar phhu avatar phughson avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar

videojs-abloop's Issues

audio not looping

I want to loop the whole video if the user wants it.For testing i enabled it by default

<link href="https://cdnjs.cloudflare.com/ajax/libs/video.js/7.4.1/alt/video-js-cdn.min.css" rel="stylesheet">
    <script src="https://cdnjs.cloudflare.com/ajax/libs/video.js/7.4.1/video.min.js"></script> 
	<script src="https://unpkg.com/videojs-abloop/dist/videojs-abloop.min.js"></script>
	<audio id="playerPFLHdOzobjFj" class="player-width player-height video-js vjs-default-skin vjs-big-play-centered" controls  preload="none"  poster="https://devzone2.filterbypass.me/s.php?k=57lt69gvoGRjIkf2fcojXCXRTrYSc4x4jN%2FESX8%2Bhgsyelg4S2op7fYnSmdHLob1&b=4">
<source src="REMOVED" type="audio/mp4">
</audio>
	<script>	
			var audio = videojs("playerPFLHdOzobjFj",{
				plugins: {
					abLoopPlugin: {
						start: 0,
						end: false,
						enabled: true,
						createButtons: true
					}
				}
			});
		</script>

However the video doesn't loop at all for me although the toggle shows loop on .I tested with chrome latest version.

Thanks for the help and the plugin

Usage with NPM?

Hello!

I was interested in using your plugin with my project, however it doesn't look like it plays nicely with NPM / Node based projects. I was wondering if you had any documentation on setting it up for this use case? Any time I import it into my project it simply errors out. If you need any additional information or a code example then please let me know.

Thanks!

Hiding the start and end button

I was wondering whether its possible to hide the start and end button as i want to loop the whole audio by default and this feature is overkill for my use case.

videojs is undefined when importing to React component

Hi! thank you very much for this plugin, I been testing it on plain html5 and works fine.
Now Im trying to use it on a React (18) project using the VideoJS component.
VideoJS Component as taken from this source.
My App.js component with pluging offset
My App.js component with pluging abloop
Note that in both cases I use and register the plugins in the same fashion. offset plugin works just fine, but then with abloop React says that videojs is undefined on abloop module.
Any help importing it to React properly?

setEnd failed

player.duration() may return NAN
that cause setEnd failed

Click does not work on apple touch devices

Thanks for the module!

Unfortunately the module does not work on Apple touch devices like the iPad.

When I touch the start or end button element, those clicks do not get triggered.

Replacing:

//create the button
  var b = player.controlBar.addChild('Button');
  if (spec.leftclick) {
    b.on('click', clickFunction(spec.leftclick));
}

with:

//create the button
  var b = player.controlBar.addChild('Button');
  if (spec.leftclick) {
    b.on('click', clickFunction(spec.leftclick));
    b.on('touchstart', clickFunction(spec.leftclick));
}

Basically inserting b.on('touchstart', clickFunction(spec.leftclick)); in line 686 fixes it for me at moment.

Don't know why the click is not triggered. Probably something else is going on and the end of the click is never reached on touch devices.

Streaming video with custom loops not working on Android

Hi,

Please see https://contentresponder.com/streaming-video-with-custom-loop-163/

It is a HLS streaming videojs video with abloop plugin. Works fine on Windows and iOS. Works on Android with a standard mp4 video. Only the combination of "streaming video (.m3u8) + abloop + android" is the issue.

But as soon as I enable the abloop plugin, video breaks with the error "the media playback was aborted due to a corruption problem or because the media used features your browser did not support chrome".

If I comment out just the line of the plugin....

plugins: {
//abLoopPlugin: {}
}

... then video loads fine on Android, but no loop feature, of course.

Why is just that one line causing the video to crash on Android devices?

Appreciate your help.

Video pauses for milli second before looping again

Hi,
When i was viewing https://cdn.rawgit.com/phhu/videojs-abloop/master/sample/basic.html link on my desktop it works perfectly fine, but when I viewed this link on an Android phone browser(chrome), just before the video loops back, there is a small lag for may be half a second. While looping back it gets stuck on 15th second for half a second and then loops back. This keeps happening every time the video loops. With a looping video it is very noticeable. Please somebody, please let me know a solution for this.

loopIfBeforeStart:false not working

Hello @phhu ! thanks in advance.

I want to reproduce video normally, and start bucle for example in second 30 to 40.

When I load the page, by default start in 30, maybe is something wrong with loopIfBeforeStart ? true / false, nothing happend.

I need use setTimeout for work with, something weird...

Thanks man!


const player = videojs('vid', {
    controls: false,
    autoplay: true,
    plugins: {
        abLoopPlugin: {
            start: 0,
            enabled: false,
            loopIfBeforeStart: false,
            createButtons: true
        }
    }
});


setTimeout(function () {
    console.log("setting new start and end...");
    player.abLoopPlugin.setStart(30).setEnd(40).enable();
}, 30000);

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.