The Frequency JavaScript video player provides a JavaScript class and a set of constructs that makes short form video playback with advertisement a simple task.

The sequence to using the Frequency JavaScript Player is as follows:

  1.  Initialize the Player.

    var player = new Frequency.Player();

    The player can be initialized with video and listener bindings so that it is one-shot ready to play or the player object can be constructed and setting the video to play and event listeners in subsequent method calls.   

    var player = new Frequency.Player(
                    undefined, {
                       video: {
                          url: 'clips.vorwaerts-gmbh.de/big_buck_bunny.mp4',
                          startPosition: 50,
                          autoplay: true
                       },
                       events: {
                          onStateChange: function(state) {
                          },
                          onProgress: function(currentTime) {
                          }, (...)
                       } 
                    }      
                 );
    
    
  2. Add player event listeners.

    player.addEventListener(Frequency.Player.Events.onError, errorHandler);
    player.addEventListener(Frequency.Player.Events.onProgress, progressHandler);
  3. Play the video.

    player.loadVideo('http://videoURL.mp4);
    player.play();

    Here is a demonstration of the video playback and event handling in a typical HTML5 playback scenario:

    Frequency Player Demo

Player Class

Player Constructor

Frequency.Player();
Frequency.Player(
   undefined, {
      video: {
      },
      events: {
      },
      (...)
   }
);

Player Methods

play

play()

Plays the currently loaded video.

Parameters:

None

Returns:

void

pause

pause()

Pauses the currently playing video.

Parameters:

None

Returns:

void


seekTo

seekTo(time:Number)

Seeks to a specified time in the video.

Parameters:

time - The time position (in seconds) in the video to jump to. 

Returns:

void

  

getDuration

getDuration()

Returns the duration of the currently playing video in seconds.

Parameters:

None

Returns:

Number - The video duration in seconds.

getState

getState()

Returns the video player's current play state.

Parameters:

None

Returns:

Number - The number representing the video playback state. (see video states).

getCurrentTime

getCurrentTime()

Returns the lapsed time since the video start in seconds.

Parameters:

None

Returns:

Number - The lapsed video playback time in seconds.

loadVideo

loadVideo(url:String)

Loads the video url specified by the url string. This does not auto play the video. The onMediaReady event would need to be monitored along with a subsequent video play() method call to cause the loaded video to play.

Parameters:

url - The url of the video to load.

Returns:

void

addEventListener

addEventListener(event:String, callback:String)

Adds a listener function for the specified event. 

Parameters:

event - The event to register for listening. (See Player events)

callback - The event handler method of code block.

Returns:

void 


removeEventListener

 
removeEventListener(event:String, callback:String)

Removes a listener function for the specified event.

Parameters:

event - The listening event. (See Player events)

callback - The event handler method or code block.

Returns:

void

Player Video Class

Player initialization

new Frequency.Player(
        undefined, {
            video: {
                url: 'http://clips.vorwaerts-gmbh.de/big_buck_bunny.mp4',
                startPosition: 50,
                autoplay: true
            },
            events: {
                onStateChange: function (state) {
                },
                onProgress: function (currentTime) {
                },(...)
            }
        }
    );


 

 



Frequency.Player

ParamTypeDescription
elementString or DOMNodeNode selector or DOMNode the player will be inserted into.
optionsObjectFrequency.Player.Options object


Frequency.Player.Options

ParamTypeDescription
videoObjectFrequency.Player.Options.Video object
eventsObjectFrequency.Player.Events object


Frequency.Player.Options.Video

ParamTypeDescriptionDefault
urlStringVideo file URL. 
startPositionNumberVideo start position.0
autoplayBooleanPlayer will/will not start playing right after loading video file.false

 

Events

Frequency.Player.Events

EventTypeDescription
onErrorFunctionAn error occured.
onReadyFunctionJS player ready for actions.
onMediaReadyFunctionMedia player ready.
onStateChangeFunctionPlayer state has changed.
onProgressFunctionPlayers progress changed.

 

States

StateValue 
UNKNOWNundefinedPlayer state is unknown, player setup process did not finished.
UNSTARTED-1Player media ready but pending play action.
ENDED0Player finished playback.
PLAYING1Player is currently playing a video.
PAUSED2Player paused.
BUFFERING3Player is buffering.
LOCKED4Player locked by internal action.

 

Methods

MethodReturn TypeDescription
play()VoidPlays the currently loaded video.
pause()VoidPauses the currently playing video.
seekTo(time:Number)VoidSeeks to a specified time in the video (in seconds).
getDuration()NumberReturns the duration of the currently playing video (in seconds).
getState()NumberReturns video players current state.
getCurrentTime()NumberReturns the elapsed time since the video start (in seconds).
loadVideo(url:String)VoidLoads video url specified by url string.
addEventListener(event:String, callback:String)VoidAdds a listener function for the specified event (see: Player events).
removeEventListener(event:String, callback:StringVoidRemoves a listener function for the specified event.