• Mail
  • twitter
  • rss

 
Table of Contents

Javascript API Functions

The documentation as listed below applies to Projekktor V0.7.17 or higher.

Instantiation

projekktor(identifier:String, config:Object, onReady:Function):Object

projekktor is the central function to create or select player instances.

creating instances

To instantiate a player use identifier to provide information which element(s) you want the player to sit on. identifier is identical to jQuery selectors.

E.g: projekktor('#player_one'); will apply to a media-tag with the id attribute player_one, projekktor('video')); will projekktorize all video elements on page and so on. Optionally you can provide a config object like this: projekktor('#player_one',{enableFlashFallback:false});

The “onReady” function will be triggered once the player has been initialized. The function gets the player Object as argument.

Chaining multiple selectors by separating them with a colon, like e.g. “video,audio” or “div.player,div.second” does not work with IE6,7,8. Single selectors like “audio” or “video” work fine.

getting instances

To get an instance previously set up as described above you can simply use projekktor(); again. This time identifier is a jQuery object or the id of the player you want to fetch. E.g: projekktor('player_a').setStop(); or projekktor($('#player_a')).setStop();

To get all available instances, use “*” as identifier. In return you will get an array of Projekktor instances.

If you are planing to use the JS API to manipulate the players, you should set the id attribute for each media element to make your live easier. If no id attribute is set, a 8-string-random id will be applied. This makes it practically impossible to identify a specific player instance during runtime. Anyhow you can of course use projekktor('*'); to grab all available instances and iterate through them.

Setters

All setters return this in order to allow method cascading.

player.addListener(event:String, callback:Object):Void

Adds a function as callback listener for the event specified. Can be applied at any time.

player.removeListener(event:String, callback:Object):Boolean

Removes a previously added function from event listening. callback must be the same entity as used in corresponding addListener call. E.g:

WIN:

var ApiTest =  function(data) {console.log(data)};
playerInstance.addListener('*',ApiTest );
playerInstance.removeListener('*',ApiTest );

FAIL:

playerInstance.addListener('*',function(data) {console.log(data)});
playerInstance.removeListener('*',function(data) {console.log(data)});

Returns TRUE on success otherwise FALSE.

player.setFile(data:Mixed, type:String):Void

Applies a single media item or a playlist. This will overwrite all current media and playlist data scheduled within in the player.

  • data - Can either be an URL or a valid playlist OBJECT. If data is an URL and type is not a valid data exchange format (xml, json or jsonp), the URL is interpreted as URL pointing to a single audio- or video-file.

player.setItem(data:Mixed, index:Number, replace:Boolean):Void

Sets, adds, removes or replaces a playlist item.

Data can be an object following the projekktor item scheme, an URL string pointing to a valid media file or NULL. If data is NULL the item at index will be removed from schedule (remove). If data is an Object and or an URL and index is NULL a new item will be injected to schedule (add). index indicates the schedule index to be affected.

add

If index is out of range (less 1 or higher than the total length of the current schedule) a new item will be appended to the schedule otherwise a new item will be created on position provided.

If replace is true and an item already exists at index the new item will not be injected but will replace the already existing one - if any.

If calling this function affects the item currently playing back, the player will instantly stop and restart playback with the new data made available and without changing the “currentItem” pointer.

If setItem affects items after the currently playing one (items of an higher index than currentItem) no restart apply.

remove

If index is out of range (less 1 or higher than the total length of the current schedule) the last scheduled item will be removed. Otherwise the item at the index provided gets dumped.

replace has no effect while performing remove actions.

If calling this function affects the item currently playing back, the player will instantly stop and will move the currentItem pointer to the previous one.

If setItem affects an item after the currently playing one (items of an higher index than currentItem) no previous-action will happen.

player.setConfig(data:Object, destIndex:Mixed):Void

Was “setItemConfig” prior V0.9.0.

Allows to set or alter item config options during runtime. data must be an object containing one or more config parameters. Not all config options are available to be set dynamically to avoid the player to crash or react in a strange way (please refer: Configuration parameters).

destIndex can either be an integer describing the destination item´s position within schedule (itemIdx) or '*' which will apply data to all items currently scheduled. If destIndex is NULL the currently played item is manipulated.

Changes on current items only take immediate effect if the player state is IDLE.

player.setPlayerPoster(url:String):Void

Sets the poster for the player. This poster is shown up once the player has been instantiated, autoplay is FALSE and the user did not hit play so far.

This method is a shortcut for setItemConfig({poster:url},0);

player.setPlayhead(position:mixed):Void (> V0.7.16)

Move the play-head to the given position.

Position can be either in seconds (number) representing the absolute second to move the playhead to or a relative value prefixed with operators ”+” or ”-” indicating the direction to move the playhead to.

E.g. assumed the playhead is on second #15, ”+5” will move it to second #20 while ”-5” will move it to #10.

If the resulting position is beyond the point of loaded media data so far and the current media type does not allow random-seeking, the play-head will be moved to the highest possible position. This function has no result. You have to listen to player events in order to check what happens. Nothing will happen at all if player´s config-option “disallowSkip” is set to TRUE.

player.setVolume(vol:mixed):Void (> V0.7.16)

Sets the Volume of the player to a percent mark indicated by vol.

Volume can be either a numeric value representing the absolute volume to set, where 0 is equal to muted and 100 indicates full throttle. Volume can also be relative - prefixed with operators ”+” or ”-” indicating the relative amount to adjust the volume to. E.g. assumed current volume is 15%, ”+5” set it to 20%, ”-5” to 10% and so on. This function has no result. You have to listen to player events in order to check what happens. Nothing will happen at all if player´s config-option “fixedVolume” is set to TRUE.

player.setFullscreen(goFullscreen:Boolean):Void

Sets the player to fullscreen / full viewport or exits from there depending if goFullscreen set to TRUE (on) or FALSE (off). Does nothing if ALLOWFULLSCREEN is FALSE or if the new state is equal to the current one.

player.setResize()

Triggers the internal “resize” event in order to rescale relative containers. This comes in handy in cases where DOM manipulations happen due to other scripts (e.g. sliders, popups etc.)

player.setSize({width:<x>, height:<y>})

Allows to set the player´s dimensions during runtime. Will also trigger “resize” in order to apply rescaling (if required).

player.setPlayPause():Boolean

Sets the player to pause if its playing or vis versa.

player.setPlay():Boolean

Sets the player to play. If its already playing no changes apply.

player.setPause():Boolean

Sets the player to pause . If its already paused no changes apply.

player.setStop():Boolean

Sets the player to stop . Will cause the playback component to stop immediately and displays the current item´s poster image. Furthermore the start-button shows up.

player.setActiveItem(item:mixed):void

Initializes playback of media item identified by the given item. Accepts an integer representing the item to be played or a “shortcut” string as follows:

Shortcuts:

  • next - Will activate the next item relatively to the currently active one
  • previous - Will activate the previous item relatively to the currently active one
  • poster - Will send the player to IDLE and display the player-poster.

If the player has been previously awakened by user-interaction or by AUTOPLAY set to TRUE, the new active item will be played back immediately.

player.setCuePoint(cuePoint:Object):void

Adds a cue point to an active player instance.

player.removeCuePoint(group:String, Idx:Integer):this

Instantly removes a cuepoint from the player instance. You must specify a “group” and the “idx” of the affected video item. In order to identify the addressed cuepoints by “group” the cuepoint´s “group” property must be priorly set accordingly.

player.setPlaybackQuality(quality:String):this

Overwrites the quality setting applied through the config option “playbackQuality”. Will force the player to instantly switch to the requested quality type. Possibe quality values are: 'small', 'medium', 'large', 'hd720', 'hd1080'.

If parameter is invalid or the requested quality isn´t available nothing will happen. Otherwise the player will trigger the “qualityChange”-event.

player.selfDestruct():void

Instantly destroys the referred instance and reconstructs its host DOM´s original state; the one before the player has been applied.

player.reset():void

Resets the instance while keeping current configuration and schedule intact. Sets the active item pointer back to zero.

player.openUrl(Object:{url:<dest>, target:string:'_self', pause:bool:false})

Opens an URL depending on “target” either in the same or in a new window, optionally pauses the player.

Getters

player.getItemCount():Number

Returns the amount of media items within the playlist.

player.getVolume():Float

Returns the sound volume of the player instance where 0 is muted and 1 is full throttle.

player.getItemIdx():Number

Returns the internal playlist index of the currently played item. Note that 0 is for the first item in line.

player.getItemId():String

Returns the unqiue ID of the currently played item if any.

player.getIsAutoslide():Boolean *

experimental

player.getItem(idx:mixed):Object

Returns one or more items identified by idx. idx can either be a numeric value describing the internal playlist position of the requested item or one of the following shortcuts:

  • 'next' to fetch the next item - relative to the currently playing one
  • 'current' (default) to fetch the data if of the item which is played back right now
  • 'previous' to fetch the previous item - relative to the currently playing one
  • '*' all items (same as getPlaylist())

Not setting “idx” will return the currently played item so you don´t have to use 'getItemIdx()' beforehand.

This method returns copies not references. To alter items you have to use setItem().

player.getLoadProgress(idx:mixed):Float

Returns how many percent of the currently played item has been loaded/buffered so far. Will instantly be 100 on media types available for random-seeking.

player.getLoadPlaybackProgress(idx:mixed):Float

Returns the current playhead position in percent relative to the currently played item´s duration.

player.getCuePoints(idx:Integer):Array

soon

player.getPosition():Number

Returns the current playhead position in milliseconds.

player.getDuration():Number

Returns the duration of the currently played item in milliseconds.

player.getTimeLeft():Number

Retruns the difference between currently played item´s duration and the playhead position in milliseconds.

player.getKbPerSec():Float

Experimental

player.getTrackId():String

Experimental

player.getPreloaderPct():Float

Experimental Moved to “Splash” plugin

player.getInFullscreen():Boolean

Returns TRUE if the player is in fullscreen / full viewport mode, otherwise FALSE.

player.getPublicName():String

Returns the player´s current unique DOM ID.

player.getMediaType():String

Returns of what type the currently played item is. (LIST GOES HERE)

player.getUsesFlash():Boolean

Returns true if the current item uses the Flash fallback component for playback.

player.getCanPlayNatively(mediaTypes:Array):Boolean

Used without parameter this method returns TRUE if the client browser is able to play back at least one media type natively. If mediaTypes parameter is set the test is performed for every media type provided and will return TRUE if one or more types specified can be played back natively.

E.g.: ['video/ogg', 'video/webm']) will return TRUE in Chrome and TRUE in FF ⇐9 but ['video/webm']) will return TRUE in Chrome only.

player.getIframeWindow():JQueryObject

If the player is in “iframe mode” this function returns the iframe´s parent window for further manipulations.

player.getIframe():JQueryObject

If the player is in “iframe mode” this function returns the iframe the player lives in.

player.getPlaylist():Object

Returns the whole currently scheduled playlist. Same as getItems('*').

player.getState(test:string):Object

If called without argument this method returns the current state of the player. You can find a list of possible states here. If “test” is not NULL and a valid state string the method will return TRUE or FALSE according to current playerstate (e.g.: getState('PLAYING') will return TRUE if the player is playing).

 
api.txt · Last modified: 2012/05/10 14:48 by operator