MediaPlayer:API:Callbacks

From Metrixstream
Revision as of 15:45, 14 June 2011 by MetrixAdmin (Talk | contribs)

Jump to: navigation, search

Contents

Getting Started

The media player has many callbacks that can be defined in JavaScript to provide more granular control over the media player and how it interacts with certain actions.

Callbacks

Callbacks are simply global JavaScript functions that the media player tries to call. If they don't exist, then the media player skips over them. It is important to always return a value or the media player will assume it was unable to successfully complete the callback.

metrix_navigateToURL

This callback is useful when the media player wants to redirect itself to a new URL and you need better control over how to perform this redirect rather than the default implementation offered by Flash.

Parameters

url
this is the URL to which the media player wants to redirect.

Example Usage

<script type="text/javascript">

 function metrix_navigateToURL(url) {
   document.location = url;
   return true;
 }

</script>

metrix_isFullscreenDisabled

This callback is useful for when you want to control access to fullscreen mode. Sometimes this is desired during chat sessions, because fullscreen mode does not allow input from the keyboard.

Parameters

This function has no parameters.

Example Usage

<script type="text/javascript">

 function metrix_isFullscreenDisabled() {
   return false;
 }

</script>

metrix_onStateChange

This callback notifies the viewer on the current state and previous state of the media player. This allows you to have control and detect errors more easily with playback.

Parameters

state
this is the current state of the media player.
lastState
this is the previous state of the media player.

Example Usage

<script type="text/javascript">

 function metrix_onStateChange(state, lastState) {
   if (state == "connectionError") {
     alert("A connection error has occurred.");
   }
   return true;
 }

</script>

metrix_onDisplayChange

This callback notifies the viewer that a display change is taking place.

Parameters

display
this is the new display mode. Allowable values are "normal" and "fullscreen".

Example Usage

<script type="text/javascript">

 function metrix_onDisplayChange(display) {
   if (display == "fullscreen") {
     alert("Enjoy the show!");
   }
   return true;
 }

</script>

metrix_filterComObject

This callback is extremely important for doing a custom live event implementation. All of the live events go through this function. Returning true will prevent the event from occurring.

Parameters

obj
this is an object with several properties. Take a look at the example below to see the implementation details.

Example Usage

<script type="text/javascript">

 function metrix_filterComObject(obj) {
   var id = obj.id;
   var msgtype = parseInt(obj.type);
   var user = obj.user;
   var msg = obj.msg;
   var host = obj.host;
   
   switch(msgtype) {
     case MCONST_CHAT: {
     } break;
     case MCONST_ENTER: {
     } break;
     case MCONST_LEAVE: {
     } break;
     case MCONST_GIFT: {
     } break;
     case MCONST_ENTER_VOYEUR: {
     } break;
     case MCONST_ACCESS_PUBLIC: {
     } break;
     case MCONST_ACCESS_PRIVATE_EXCLUSIVE: {
     } break;
     case MCONST_ACCESS_PRIVATE_GROUP: {
     } break;
     case MCONST_MODE_CHANGE: {
     } break;
     case MCONST_SHUTDOWN: {
     } break;
   }
 
   return false;
 };

</script>

metrix_updateRoster

This callback allows you to build your own chat roster of who is viewing the live event.

Parameters

user
this is the username of the viewer being updated.
host
this is whether or not the viewer is the host.
add
this is a boolean determining if the viewer is entering or leaving the event.

Example Usage

<script type="text/javascript">

var roster = {};

function metrix_updateRoster(user, host, add) {
  if (add) {
    roster[user] = true;
  } else {
   delete roster[user];
  }
  return true;
}

metrix_onPlayheadUpdate

This callback allows you to dynamically adjust your playhead cursor as your media plays.

Parameters

obj
this is an object with several properties.
curTime
this is the current time in seconds of the media playing.
totalTime
this is the total time in seconds of the media playing.
playerId
this is the HTML DOM id of the media player.

Example Usage

<script type="text/javascript">

var roster = {};

function metrix_updateRoster(user, host, add) {
  if (add) {
    roster[user] = true;
  } else {
   delete roster[user];
  }
  return true;
}
Personal tools