@avvio-reply/jplayer
v1.2.7
Published
Stitched-frame player with custom event controls
Downloads
43
Readme
JPlayer
Writes image frames from stitched content to target canvas.
How it works
JPlayer is a configurable stills player to create highly flexible video playback. Finite control is possible through a 'frame event' mechanism.
Playback can be either forward or reverse, with options to loop, even down to a subset of frames if desired.
Event triggers can be configured by frame number or by custom naming allowing intuitive and descriptive event handlers to be written.
JPlayer requires Preloader and will include this when installed.
REQUIRE
require('@avvio-reply/jplayer')(require('jquery'))
USAGE - Configuration:
Define an object with one or more scenes with the following schema:
var root = '/content/images/scenes/'
, content = {
scenes: [
{
name: "<scene-name>", // key name of scene (some methods accept this name as identifier)
preload: 100, // percentage of resources that must be loaded before the scene is ready to play
motion: { // MOTION Schema:
catalog: root, // root of stitched image resources
sheetfrom: 1, // start of stitched image file range - stitched image resources must be named in numerical sequential order
sheetto: 29, // end of stitched image file range
sheetsize: 4, // the number of stills within the file - stills are assumed to be arranged left to right
framerate: 30, // playback number of frames per second for this scene
framewidth: 832, // width of a single frame within stitched files - all frames must have equal dimensions
frameheight: 468, // height of a single frame within stitched files - all frames must have equal dimensions
loop: false // True or False tells JPlayer whether to run through all frames in a continuous loop
},
events: { // EVENTS Schema:
custom: { // custom group of named events
<named-event-a>: [ 1 ], // named event providing the frame or frames that trigger the name
<named-event-b>: [ 116, 127 ] // named event providing the frame or frames that trigger the name
}
}
}
}
USAGE - Insantiation:
this.$canvas.jPlayer({
scenes: Config.content
, framerate: 20
, regulateFramerate: false
, frameEventCallback: function(e){
if (e.events.introStart) {
} else if (e.events.introOver) {
/* animated intro complete - load next question */
self.renderQuestion();
}
else if (e.events.resultStart){
self.assets['whistle'].play();
}
else if (e.events.resultKick){
self.assets['kick'].play();
}
else if (e.events.resultKnown){
/* ensure result audios are reset */
self.assets['goal'].pause();
self.assets['goal'].currentTime = 0;
self.assets['miss'].pause();
self.assets['miss'].currentTime = 0;
var result = self.isLastAnsweredCorrectly() ? 'goal' : 'miss';
if (self.assets[result])
self.assets[result].play();
/* update the score indicator */
$($('#bonusScoreList li').get(self.currentQuestion-1))
.addClass('is-' + result);
}
else if (e.events.resultOver) {
if (self.currentQuestion == 5){
endLoop = true;
setTimeout(function(){
location.href = '/';
}, 3500);
} else
{ /* re-run intro because another question is pending */
self.playScene('intro');
}
}
}
, preloadCallback: function(e){}
, endLoopCallback: function(e){}
, sceneCreatedCallback: function(e){}
, sceneReadyCallback: function(e){}
});
USAGE - Methods
Play
$('#user-canvas').jPlayer('play')
Stop
$('#user-canvas').jPlayer('stop')
SetSceneByNumber
$('#user-canvas').jPlayer('setSceneByNumber', newSceneNumber)
SetSceneByName
$('#user-canvas').jPlayer('setSceneByName', newSceneName)
Forward
$('#user-canvas').jPlayer('forward')
Reverse
$('#user-canvas').jPlayer('reverse')
Toggle
$('#user-canvas').jPlayer('toggle')
Playing
$('#user-canvas').jPlayer('playing')
GetScene
$('#user-canvas').jPlayer('getScene')
SetFrame
Change the frame number during playback whether forward or reverse.
$('#user-canvas').jPlayer('setFrame', (int)newFrame)
SetFrameRate
Changes the current playback frame-rate (per second). Better results are possible when newRate divides evenly into 60
given HTML5 canvas is 60fps.
Option regulate is only effective when JPlayer is in differential mode. Regulate attempts to correct framerate syncing
with uneven framerates, such as 24fps.
$('#user-canvas').jPlayer('setFramerate', (int)newRate, (bool)regulate)
GetPreloadState
Returns object representing the load state of required resources as determined by the player configuration.
$('#user-canvas').jPlayer('getPreloadState')
IsAtStart
Returns bool True/False whether the current scene is the first scene:
$('#user-canvas').jPlayer('isAtStart')
IsAtEnd
Returns bool True/False whether the current scene is the last scene:
$('#user-canvas').jPlayer('isAtEnd')
LOCAL DEV:
"@avvio-reply/jplayer": "file:///development/node/modules/jplayer"