MediaPlayer:API:Calls
Contents |
Getting Started
The media player has several callbacks and 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>