MediaPlayer:API:Calls

From Metrixstream
Jump to: navigation, search

Contents

Getting Started

The media player has functions available to control it as you see fit. This document will go over them all in detail.

Functions

All functions must be called via JavaScript on the actual DOM element of the media player. This id is exposed in the getCustomPlayerEmbedCode macro.

The examples below will leverage the getDefaultPlayer() JavaScript shown in following code block.

<script type="text/javascript">

 function getPlayer(name) {
  var isIE = navigator.appName.indexOf("Microsoft") != -1;
  var player = (isIE) ? window[name] : document[name];
  return player;
 }

 function getDefaultPlayer() {
   return getPlayer("mtxPlayer");
 }

</script>

metrix_playMedia

This function allows you to play the existing media at its current position of it was paused or stopped.

Parameters

This function has no parameters.

Example Usage

<script type="text/javascript">

 getDefaultPlayer().metrix_playMedia();

</script>


metrix_stopMedia

This function allows you to stop the playback of media. If the media is already stopped, this function will have no affect.

Parameters

This function has no parameters.

Example Usage

<script type="text/javascript">

 getDefaultPlayer().metrix_stopMedia();

</script>

metrix_seekMedia

This function allows you to seek to a specific location within the media.

Parameters

percentage
this is a normalized normalized offset between 0 and 1. If the media is 60 seconds long, then 0.5 would represent 30 seconds.

Example Usage

<script type="text/javascript">

 getDefaultPlayer().metrix_seekMedia(0.5);

</script>

metrix_isPlaying

This function determines whether or not there is media in the play state.

Parameters

This function has no parameters.

Example Usage

<script type="text/javascript">

 if (getDefaultPlayer().metrix_isPlaying()) {
   alert("this video is playing");
 }

</script>

metrix_muteVolume

This function mutes the volume of the media player. Un-muting the volume will bring the volume back to its original state before the mute took place.

Parameters

This function has no parameters.

Example Usage

<script type="text/javascript">

 getDefaultPlayer().metrix_muteVolume();

</script>

metrix_unmuteVolume

This function un-mutes the volume of the media player. This will return the volume back to the original state it was in at the time of muting.before the mute took place.

Parameters

This function has no parameters.

Example Usage

<script type="text/javascript">

 getDefaultPlayer().metrix_unmuteVolume();

</script>

metrix_setVolume

This function sets the volume of the media player.

Parameters

volume
this is a normalized offset between 0 and 1. Setting the volume to 1 will maximize the loudness of the volume.

Example Usage

<script type="text/javascript">

 getDefaultPlayer().metrix_setVolume(1);

</script>

metrix_getVolume

This function gets the current volume of the media player.

Parameters

This function has no parameters.

Example Usage

<script type="text/javascript">

 alert("The current volume is: " + getDefaultPlayer().metrix_getVolume());

</script>

metrix_isMuted

This function determines whether or not the media player is muted.

Parameters

This function has no parameters.

Example Usage

<script type="text/javascript">

 if (getDefaultPlayer().metrix_isMuted()) {
   alert("The player is muted.");
 }

</script>

metrix_playSound

This function allows playback of an audio file via a URL. This is useful for adding audio feedback for certain actions (such as a cash register sound during a tip).

Parameters

src
this is a URL to an audio file. The following formats are supported: mp3 and wav.

Example Usage

<script type="text/javascript">

 getDefaultPlayer().metrix_playSound("/static/sounds/cashregister.mp3");

</script>

metrix_sendChat

This function sends a chat message.

Parameters

message
this is the actual message being sent to the other viewers.

Example Usage

<script type="text/javascript">

 getDefaultPlayer().metrix_sendChat("hey there, this is a great show!");

</script>

metrix_toggleFullScreenMode

This function toggles with media player into and out of fullscreen mode.

Parameters

This function has no parameters.

Example Usage

<script type="text/javascript">

 getDefaultPlayer().metrix_toggleFullScreenMode();
</script>

metrix_getUserId

This function gets the current viewer's user id. This function will return 0 if the viewer is the actual event host and -1 if the viewer is not logged in.

Parameters

This function has no parameters.

Example Usage

<script type="text/javascript">

 alert("Your user id is: " + getDefaultPlayer().metrix_getUserId());

</script>

metrix_getUserName

This function gets the current viewer's username. This function will return a unique username for anonymous users in the format of "Guest:XXXXXXXXXX", where the X's are digits. This function will do its best to keep the anonymous username persistent from session to session.

Parameters

This function has no parameters.

Example Usage

<script type="text/javascript">

 alert("Your username is: " + getDefaultPlayer().metrix_getUserName());

</script>

metrix_isAnonymous

This function determines if the viewer is logged in or not.

Parameters

This function has no parameters.

Example Usage

<script type="text/javascript">

 if (getDefaultPlayer().metrix_isAnonymous()) {
   alert("You are anonymous.");
 }

</script>

metrix_isHost

This function determines if the viewer is the event host.

Parameters

This function has no parameters.

Example Usage

<script type="text/javascript">

 if (getDefaultPlayer().metrix_isHost()) {
   alert("You are the event host.");
 }

</script>
Personal tools