Skip to content

Instantly share code, notes, and snippets.

@db48x
Forked from boazsender/popcorn-api.js
Created February 25, 2011 18:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save db48x/844211 to your computer and use it in GitHub Desktop.
Save db48x/844211 to your computer and use it in GitHub Desktop.
// Popcorn Instance Methods
var p = Popcorn( "#video" )
p.play()
// Play the video (Native "pass through" method)
// Returns the Popcorn instance object
p.load()
// Load the video (Native "pass through" method)
// Returns the Popcorn instance object
p.pause()
// Pause the video (Native "pass through" method)
// Returns the Popcorn instance object
p.mute()
// Toggle mute (Native "pass through" method)
// Returns the Popcorn instance object
p.volume( arg )
// Get and set the volume (Native "pass through" method)
// Returns the Popcorn instance object
p.duration()
// Get the duration (Native "pass through" method)
// Returns the Popcorn instance object
p.currentTime( [arg] )
// Get and set the current time (Native "pass through" method)
// Getter returns current time
// Setter returns the Popcorn instance object
p.playbackRate( [arg] )
// Get and set the playback rate (Native "pass through" method)
// Getter returns playback rate
// Setter returns the Popcorn instance object
p.exec( time, callback )
// Bind a callback function to a time in miliseconds (New Popcorn.js method)
// Returns the Popcorn instance object
p.trigger( type, data )
// Trigger an event (New Popcorn.js method)
// Returns the Popcorn instance object
p.listen( eventtype, callback )
// Bind to an event (New Popcorn.js method)
// Returns the Popcorn instance object
p.unlisten( eventtype, 'callbackbackname' )
// Unbind an event listen (New Popcorn.js method)er
// Returns the Popcorn instance object
p.removeTrackEvent( id )
// Remove a track event (New Popcorn.js method)
// Returns undefined
p.getTrackEvents()
// Get the track events (New Popcorn.js method)
// Returns the track events
p.getLastTrackEventId()
// Get the id of the last track event that was added (New Popcorn.js method)
// Returns the id of the last track event added
p.removePlugin( 'pluginname' )
// Remove a plugin from the registry (New Popcorn.js method)
//Popcorn HTMLVideoElement reference
Popcorn.video: HTMLVideoElement
//Popcorn Utility Methods
Popcorn.plugin( 'pluginname', definition, manifest )
// Register a plugin with popcorn
// Definition can be a function or an object
// Manifest is an object that describes the options that the plugin uses
// Returns reference to the plugin when possible
Popcorn.forEach( object, callback( value, index ), context )
// ES5 compliant foreach
// Returns the object that you passed into it
Popcorn.extend( object, [ argN ] )
// Merge two objects
// Returns the extended object
Popcorn.sizeOf( object )
// Get number of properties in an object
// Returns the number of properties in the object
Popcorn.nop()
// A no operation function expression
// Returns undefined
// Popcorn Events
loadstart, progress, suspend, emptied, stalled, play, pause,
loadedmetadata, loadeddata, waiting, playing, canplay, canplaythrough,
seeking, seeked, timeupdate, ended, ratechange, durationchange, volumechange
{
// Plugin meta data
// will be used in the Butter ui
about: {
name: "name of plugin",
version: "semantic version",
author: "author name",
website: "author url"
},
// Object representation of the plugin options
// a form will be constructed against this object
options: {
start : {elem:'input', type:'number', label:'In'},
end : {elem:'input', type:'number', label:'Out'},
target : 'id-selector',
text : {elem:'input', type:'text', label:'Text'}
}
}
/* Pattern 1
* Provide a function that returns an object
*/
// You could define plugin-wide variables out here, but then they
// could shadow variables declared by other plugins or by other
// scripts used alongside Popcorn
(function () {
// Define plugin-wide variables in here instead
Popcorn.plugin( "pluginName" , function( options ) {
// setup code, fires on initialization
// options refers to the options passed into the plugin on init
// this refers to the popcorn object
// You are required to return an object
// with a start and end property
// it may optionally have a _setup method
return {
_setup : function( options ) {
// setup code, fires on initialization
// options refers to the options passed into the plugin on init
// this refers to the popcorn object
},
start: function( event, options ) {
// fires on options.start
// event refers to the event object
// options refers to the options passed into the plugin on init
// this refers to the popcorn object
},
end: function( event, options ) {
// fires on options.end
// event refers to the event object
// options refers to the options passed into the plugin on init
// this refers to the popcorn object
}
};
},
{
// manifest definition here
});
})();
/* Pattern 2
* Provide an object
*/
// You could define plugin-wide variables out here, but then they
// could shadow variables declared by other plugins or by other
// scripts used alongside Popcorn
(function () {
// Define plugin-wide variables out here instead
Popcorn.plugin( "pluginName" , {
_setup : function( options ) {
// setup code, fires on initialization
// options refers to the options passed into the plugin on init
// this refers to the popcorn object
},
start: function( event, options ){
// fires on options.start
// event refers to the event object
// options refers to the options passed into the plugin on init
// this refers to the popcorn object
},
end: function( event, options ){
// fires on options.end
// event refers to the event object
// options refers to the options passed into the plugin on init
// this refers to the popcorn object
},
manifest: {
// manifest definition here
}
});
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment