MediaPlayer:API:Callbacks
MetrixAdmin (Talk | contribs) (Created page with "== 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 cert...") |
MetrixAdmin (Talk | contribs) |
||
Line 5: | Line 5: | ||
== Callbacks == | == 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. | + | 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 == | == metrix_navigateToURL == | ||
Line 22: | Line 22: | ||
function metrix_navigateToURL(url) { | function metrix_navigateToURL(url) { | ||
document.location = url; | document.location = url; | ||
+ | return true; | ||
+ | } | ||
+ | |||
+ | </script> | ||
+ | |||
+ | == metrix_isFullscreenDisabled == | ||
+ | |||
+ | This callback is useful for when you want to control access to fullscreen mode. | ||
+ | |||
+ | === 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."); | ||
+ | } | ||
} | } | ||
</script> | </script> |
Revision as of 17:17, 26 March 2011
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.
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.
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."); } } </script>