Player
When accessing player instances on a page with the flowplayer() or
$f() function, Player objects are returned. You can think of it as
a DVD player with playback buttons such as start, stop and pause.
In this section:
Player methods
| Method | Returns | Description |
|---|---|---|
|
addClip(clip, index) |
since 3.1.1. Add's a clip to the playlist. First argument is the clip to be added which is either a URL as a string or is a clip configuration that you can specify as json object. The index argument specifies the position where clip is added in the playlist. If the clip object contains a | |
|
close() |
Closes all connections between the player and the server. This method is usually automatically called for you but in some cases you may want to do this yourself. | |
|
getClip() | ||
|
getCommonClip() | ||
|
getControls() | ||
|
getFlashParams() | ||
|
getIndex() |
integer |
Returns the zero-based index of the Player when there are multiple Players on the page. Remember that the index of a Player is not the same as the order in which Players occur in elements on the page. The index number is the order in which the Players were created. Example: |
|
getParent() |
Element |
Returns the Player's containing DOM element. |
|
getLogo() | ||
|
getPlay() | ||
|
getPlaylist() | ||
|
getPlugin() | ||
|
getScreen() | ||
|
getState() |
integer |
Returns the state of the player. Possible values are:
|
|
getStatus() |
Object |
Returns a set of status information in a single call. Some plugins may frequently need lots of information. One such plugin is the HTML-based controls plugin. By returning state information in a single call we can greatly reduce CPU intensive Flash/JavaScript communication. The following object is returned with the following initial values: { |
|
getTime() |
integer |
Returns the current time, in seconds, of the current clip. |
|
getVersion() |
Array |
Returns the Flowplayer version as an array. Depending on your version and whether the player is loaded or not this method returns different results. Example return value: |
|
getVolume() |
integer |
Returns the player's current volume setting as an integer between 0-100. This returns the volume setting even if the player is muted. |
|
hide() |
Makes the player hidden in a way that it keeps running. By default Flash works in a way that if you place any HTML on top of it the Flash still shows through. Any z-indexing or CSS trick won't work. This method helps you with these problems by making the Flash object invisible until it is revealed again by a call to | |
|
id() |
String |
Returns the id of the container of the Player. |
|
isFullscreen() |
boolean |
Returns |
|
isHidden() |
boolean |
Returns |
|
isLoaded() |
boolean |
Returns |
|
isPaused() |
boolean |
Returns |
|
isPlaying() |
boolean |
Returns |
|
load([callback]) |
This call will save any html or splash image that was in the container and loads a Player flash component that replaces the html or splash image. This may take some time depending on the user's bandwidth and whether Flash is cached on the user's browser or not. If the container contained html or a splash image, then the player will not be shown until it is clicked; the click will issue an | |
|
loadPlugin(name, url, [properties], [callback]) |
Loads a Flash plugin in the player. name specifies a unique name for the plugin that you can later use in calls to | |
|
mute() |
Mutes the player. The difference between this and | |
|
pause() |
Pauses the currently playing clip. | |
|
play() |
Starts playback of the current clip. | |
|
play(index) |
Starts playback of the clip specified by | |
|
play(clip) |
Plays the clip specified by the | |
|
play([clip, clip ...]) |
Play the playlist specified by the array argument. Each | |
|
play(clip, instream) |
since 3.1.1. Plays the clip specified by the | |
|
reset(plugin) |
If you have moved your screen or controlbar, this call moves them back to their original positions and size. You can optionally specify an array of plugin names (strings) that you also want to reset to their original state. For example: | |
|
resume() |
Resumes the currently paused clip. | |
|
seek(seconds) |
Seeks to the specified time of the current clip, in seconds. If using default URL-based streaming provider then the buffer must have loaded to the point of seeking. When using streaming server this is not required. | |
|
getClip() | ||
|
getPlaylist() | ||
|
setVolume(integer) |
Sets the volume. Accepts an integer between 0-100. 0 is totally muted. | |
|
show() |
If the player was hidden with a call to | |
|
startBuffering() |
Starts downloading video data from the server. | |
|
stop() |
Stops the current clip. | |
|
stopBuffering() |
Stops downloading video data from the server. | |
|
toggle() |
boolean |
Toggles the state between play and pause. Returns the new state of the player, with |
|
toggleFullscreen() |
boolean |
since 3.1.1. Toggles the state between fullscreen and normal mode. Returns the new state of the player, with |
|
unload() |
Unloads the player Flash component and replaces it with the original HTML content of the container element. This method does nothing if there was no HTML in the container. Otherwise it first fires an | |
|
unmute() |
Resumes the volume level that was set before the player was muted. |
Accessing objects of a Player
| Method | Returns | Description |
|---|---|---|
|
getClip() |
Returns the current clip. | |
|
getClip(index) |
Returns the clip from the playlist specified by | |
|
getCommonClip() |
Returns the common clip object with properties common to all clips of the playlist. If you add event listeners to this object, they will be common to all clips of the playlist. | |
|
getPlaylist() |
Returns the playlist of the player as an array of Clip objects. | |
|
getControls() |
Returns the first controlbar that is configured for the player. Shorthand for | |
|
getConfig(copy) |
Object |
Returns the active configuration as an object. You can modify this object causing the configuration to change, however, it is recommended that you only use the API methods after setting the initial configuration. Use for example the clip's |
|
getFlashParams() |
Object |
Returns the configuration object that was supplied upon setup for |
|
getLogo() |
Returns the logo. Shorthand for | |
|
getPlay() |
Returns the play button. Shorthand for | |
|
getPlugin(name) |
Returns the plugin with the given name. You name
a plugin in the configuration or via the
| |
|
getScreen() |
Returns the video screen. Shorthand for | |
|
setClip(clip) |
Replaces the current playlist with a playlist consisting of a single clip. | |
|
setPlaylist([clip,...]) |
Replaces the current playlist with a new one. The playlist is given as an array of clips that can be either stings (urls) or Clip configuration objects that you can specify for example in json. All common clip properties are preserved. After this an |
Player events
Each Player fires events that can inform you of changes in the Player
and of actions the Player intends to take or has just taken. The event
listener receives as its this variable a reference to the current
Player instance.
Before events are marked in italics in the table below. Not all events
have a before event. The 'Cancel action' column says what will happen
when a before event listener returns false.
| Event | When does it fire? | Cancel action |
|---|---|---|
|
onBeforeClick |
This event fires: after Flowplayer has been installed on the container, and the container element is not empty (it contains html), and it is clicked. Flowplayer's Note: when a new Player is installed, Flowplayer
will |
Flowplayer will not be installed. |
|
|
The Before the The |
Player will not be loaded. |
|
|
Flowplayer's default After the Player has been unloaded from a container that
contains html, clicking the container will (again) fire
the These events will only fire when the container was not empty. |
Player is not unloaded. |
|
|
This fires when the mouse pointer moves into the player area. | |
|
|
This fires when the mouse pointer moves out of the player area. | |
|
|
This fires when a user presses a key on the keyboard while the Player has the focus. The code corresponding to the key which has been pressed is provided as the first argument to the event listener. A list of different key codes is given here. |
Default keyboard actions are ignored. (By default, the spacebar toggles between playing and paused states, and the arrow keys seek backward and forward.) |
|
|
This fires when the volume level is changed (via any of
the |
Volume level is not changed. |
|
|
This fires when the player is muted. |
Volume level is not changed. |
|
|
This fires when the player is unmuted. |
Player stays muted. |
|
|
This fires when full screen mode is entered. |
Full screen mode will not be entered. |
|
|
This fires when full screen mode is exited. (Unfortunately, there is currently no 'onBeforeFullscreenExit' event. This is because the current implementation of Flash does not permit this action to be cancelled.) | |
|
|
Since 3.1.1. This fires when a clip was added to the playlist
via the | |
|
|
This fires when the playlist is swapped out for another. This
typically happens when the | |
|
|
This fires when an error occurs inside the player. The event
listener receives two arguments: |
Error Codes
|
100 |
Plugin initialization failed |
|---|---|
|
200 |
Stream not found |
|
201 |
Unable to load stream or clip file |
|
202 |
Provider specified in clip is not loaded |
|
300 |
Player initialization failed |
|
301 |
Unable to load plugin |
|
302 |
Error when invoking plugin external method |
|
303 |
Failed to load resource such as stylesheet or background image |
Playlists
A playlist in Flowplayer is simply an array of clips. You can specify
a playlist in the initial configuration, or you can set it with a call
to the setPlaylist() of the Player object:
/ Set a playlist in the initial configuration /
$f("player", "flowplayer.swf", {
// playlist with two entries
playlist: [
// playlist entry as a string means the url
'http://stream.flowplayer.org/KimAronson-TwentySeconds58192.flv',
// playlist entry with custom duration
{
url: 'http://stream.flowplayer.org/KimAronson-TwentySeconds59483.flv',
duration: 10
}
],
// show playlist buttons in controlbar
plugins: {
controls: {
playlist: true
}
}
});
/* Set a playlist in run time */
$f("player").setPlaylist( [
// playlist entry as a string means the url
'http://stream.flowplayer.org/KimAronson-TwentySeconds58192.flv',
// playlist entry with custom duration
{
url: 'http://stream.flowplayer.org/KimAronson-TwentySeconds59483.flv',
duration: 10
}
]);
Common Clip
Common clip is an important concept in Flowplayer. It specifies
properties and event listeners that are common to all clips in the
playlist. For example, you can set one onStart event listener that
will be called for each clip that starts playing in the
playlist. Internally the common clip is a special entry of the
playlist array with index -1. When replacing the playlist, this entry
is preserved. Each clip can also have its own value for the properties
and have own event listeners. These override those of common clip. You
can also assign event listeners to both the common clip and the
playlist entries. In this case playlist events are called before the
common clip events. If you return false from the playlist event then
common clip event will not be called. This mechanism is also called
"event bubbling". See our event bubbling
demo.
Examples:
/ Set common clip properties and event listeners in the initial
* configuration /
$f("player", "flowplayer.swf", {
// common clip: these properties are common to all clips of the
// playlist
clip: {
duration: 5,
// set a common clip event listener
onStart: function(clip) {
alert("Playing");
}
},
// onStart event is called for both of these clips
playlist: ['video1.flv', 'video2.flv']
});
/* Set common clip properties and event listeners in run-time */
// register event listener with common clip
$f("player").onStart(function() {
alert("Playing");
});
// this does the same thing
$f("player").getCommonClip().onStart(function() {
alert("Playing");
});
// if you want to register a listener to a specific clip *only*
$f("player").getClip(1).onStart(function() {
alert("Playing");
});
It is important to note that internally the playlist is always created
and that it has zero or more entries. If you define a clip object and
no playlists, then that clip's properties become the properties of the
common clip and the clips's url is placed in the first (and only)
playlist entry. When modifying the playlist programmatically using the
play(clip) method, all the common clip properties are preserved.
See also common clip configuration.