The API defines handler interfaces for various player events. With these handlers, different implementations can be provided to build a rich multimedia experience.
The following table describes the various handlers and supported player events
| Handler | Event types | Description |
|---|---|---|
| PlayerStateHandler | PlayerStateEvent.State.Ready |
player is initialized and ready for interaction |
PlayerStateEvent.State.BufferingStarted |
player has started buffering | |
PlayerStateEvent.State.BufferingFinished |
player has stopped buffering | |
PlayerStateEvent.State.DimensionChangedOnVideo |
the dimension of the player has changed to match the size of the current media, especially video | |
PlayerStateEvent.State.FullScreenStarted |
the player has entered into fullscreen display mode | |
PlayerStateEvent.State.FullScreenFinished |
the player has entered normal display mode from fullscreen | |
| PlayStateHandler | PlayerState.State.Started |
playback has started |
PlayerState.State.Finished |
playback has finished | |
PlayerState.State.Paused |
playback is currently paused | |
PlayerState.State.Stopped |
playback is currently stopped | |
| LoadingProgressHandler | LoadingProgressEvent |
fired when media download progress has changed |
| MediaInfoHandler | MediaInfoEvent |
fired when media metadata is available |
| DebugHandler | DebugEvent.MessageType.Info |
fired for typical INFO level messages |
DebugEvent.MessageType.Error |
fired when severe error occurs |
Here is an example:
SimplePanel panel = new SimplePanel(); // create panel to hold the player
try {
// get any player that can playback media
AbstractMediaPlayer player = PlayerUtil.getPlayer(Plugin.AUTO,
"http://www.example.com/media.mp3", false, "50px", "100%");
player.addDebugHandler(new DebugHandler() {
@Override
public void onDebug(DebugEvent event) {
switch(event.getMessageType()) {
case Info:
case Error:
GWT.log(event.getMessage());
}
}
});
panel.setWidget(player); // add player to panel.
} catch(LoadException e) {
// catch loading exception and alert user
Window.alert("An error occured while loading");
} catch (PluginVersionException ex) {
// catch PluginVersionException, thrown if required plugin version is not found
panel.setWidget(PlayerUtil.getMissingPluginNotice(e.getPlugin()));
} catch(PluginNotFoundException e) {
// catch PluginNotFoundException, thrown if no plugin is not found
panel.setWidget(PlayerUtil.getMissingPluginNotice(e.getPlugin()));
}