Javascript API
Introduction and setup
The API allows you to control and get information about media playback and audio from the vzaar player using JavaScript.
To enable the JavaScript API, the flashvar apiOn=true must be passed in to the player.
When the player is ready to receive calls it will execute the JavaScript function vzaarPlayerReady(). This will allow any setup code to run; for example, to establish an event listener.
To obtain the reference to the player for calling the API functions, use getElementById(player object id). For example vzPlayer = document.getElementById("video"); This code needs to be positioned inside the vzPlayerReady() function.
Available functions
The following functions are available from JavaScript and assume that the reference to the player is called vzPlayer.
vzPlayer.play2():void
Plays the video, if it is paused or not yet started. Replays
the video if it is at the end.
vzPlayer.pause():void
Pauses the video if it is playing.
vzPlayer.playPause():void
Toggles the play/pause status of the video, i.e. plays the
video if paused or pauses it if it is playing. Plays the video if
it has not yet started. Replays the video if it is at the
end.
vzPlayer.seekTo(seconds:Number):void
Seeks to the specified position in the video (in
seconds).
vzPlayer.getTime():Number
Returns the current play time of the video in seconds (to 2
decimal places).
vzPlayer.getTotalTime():Number
Returns the duration of the video in seconds (to 2 decimal
places).
vzPlayer.setVolume(volume:int):void
Sets the volume of the player to the specified value (from 0 to
5).
vzPlayer.getVolume():int
Returns the current volume of the player (from 0 to
5).
vzPlayer.muteOn():void
Mutes the player if it is currently unmuted.
vzPlayer.muteOff():void
Unmutes the player if it is currently muted.
vzPlayer.muteToggle():void
Toggles the mute status of the player on or off, depending on
its current status.
vzPlayer.getMute():Boolean
Returns the current mute status of the player
(true/false).
vzPlayer.loadVideo(id:int):void
Loads the video specified by its id number.
vzPlayer.playlistPlay(index:int):void
Starts playing a video from the current playlist, specified by
its position in the playlist.
vzPlayer.addEventListener(event:String,
listener:String):void
Listens for events dispatched from the player and executes the
listener function.
The following events can be listened for:
playState
Dispatched when playback begins ("mediaStarted") and ends
("mediaEnded").
progress
Dispatched every 10% of the media viewed ("10percent",
"20percent", etc).
interaction
Dispatched on the following player interactions: "pause",
"resume", "fullscreenon", "fullscreenoff", "scalingon",
"scalingoff", "soundOn", "soundOff", "seekbar",
"seekbarhandle".
Example code
// set up event listener for player status
function vzaarPlayerReady() {
vzPlayer = document.getElementById("video");
vzPlayer.addEventListener("playState", "showPlayerStatus");
alert("ready");
}
function showPlayerStatus(state) {
alert(state);
}
// play the video
function playVzaarVideo() {
vzPlayer.play2();
}
// get the video duration
function getVzaarVideoDuration() {
totalTime = vzPlayer.getTotalTime();
alert(totalTime);
}