com.bramosystems.oss.player.core.client
Class AbstractMediaPlayer

java.lang.Object
  extended by com.google.gwt.user.client.ui.UIObject
      extended by com.google.gwt.user.client.ui.Widget
          extended by com.google.gwt.user.client.ui.Composite
              extended by com.bramosystems.oss.player.core.client.AbstractMediaPlayer
All Implemented Interfaces:
HasMediaMessageHandlers, HasMediaProgressHandlers, HasMediaStateHandlers, HasPlayStateHandlers, com.google.gwt.event.dom.client.HasKeyDownHandlers, com.google.gwt.event.dom.client.HasKeyPressHandlers, com.google.gwt.event.dom.client.HasKeyUpHandlers, com.google.gwt.event.dom.client.HasMouseDownHandlers, com.google.gwt.event.dom.client.HasMouseMoveHandlers, com.google.gwt.event.dom.client.HasMouseUpHandlers, com.google.gwt.event.logical.shared.HasAttachHandlers, com.google.gwt.event.shared.HasHandlers, com.google.gwt.user.client.EventListener, com.google.gwt.user.client.ui.IsWidget
Direct Known Subclasses:
CustomAudioPlayer, CustomVideoPlayer, DivXPlayer, FlashMediaPlayer, NativePlayer, Player, PlayerWrapper, QuickTimePlayer, VLCPlayer, WinMediaPlayer, YouTubePlayer

public abstract class AbstractMediaPlayer
extends com.google.gwt.user.client.ui.Composite
implements HasMediaStateHandlers, com.google.gwt.event.dom.client.HasMouseMoveHandlers, com.google.gwt.event.dom.client.HasMouseDownHandlers, com.google.gwt.event.dom.client.HasMouseUpHandlers, com.google.gwt.event.dom.client.HasKeyDownHandlers, com.google.gwt.event.dom.client.HasKeyUpHandlers, com.google.gwt.event.dom.client.HasKeyPressHandlers

Abstract implementation of a media player. It implements the handling of MediaStateListeners.

Author:
Sikiru Braheem

Nested Class Summary
 
Nested classes/interfaces inherited from class com.google.gwt.user.client.ui.UIObject
com.google.gwt.user.client.ui.UIObject.DebugIdImpl, com.google.gwt.user.client.ui.UIObject.DebugIdImplEnabled
 
Field Summary
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
AbstractMediaPlayer()
          Constructor method.
 
Method Summary
 com.google.gwt.event.shared.HandlerRegistration addDebugHandler(DebugHandler handler)
          Adds the specified debug handler to the player
 com.google.gwt.event.shared.HandlerRegistration addKeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler handler)
          Adds the key down handler to the player
 com.google.gwt.event.shared.HandlerRegistration addKeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler handler)
          Adds the key press handler to the player
 com.google.gwt.event.shared.HandlerRegistration addKeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler handler)
          Adds the key up handler to the player
 com.google.gwt.event.shared.HandlerRegistration addLoadingProgressHandler(LoadingProgressHandler handler)
          Adds the specified loading progress handler to the player
 com.google.gwt.event.shared.HandlerRegistration addMediaInfoHandler(MediaInfoHandler handler)
          Adds the specified MediaInfo handler to the player
 com.google.gwt.event.shared.HandlerRegistration addMouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandler handler)
          Adds the mouse down handler to the player
 com.google.gwt.event.shared.HandlerRegistration addMouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler handler)
          Adds the mouse move handler to the player
 com.google.gwt.event.shared.HandlerRegistration addMouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler handler)
          Adds the mouse up handler to the player
 com.google.gwt.event.shared.HandlerRegistration addPlayerStateHandler(PlayerStateHandler handler)
          Adds the specified player-state handler to the player
 com.google.gwt.event.shared.HandlerRegistration addPlayStateHandler(PlayStateHandler handler)
          Adds the specified play-state handler to the player
protected  void addToPlayerReadyCommandQueue(java.lang.String key, com.google.gwt.user.client.Command command)
          Adds the specified command to this players' command queue.
protected  void fireDebug(java.lang.String message)
          Convenience method to fire DebugEvent's with informational messages on registered handlers.
protected  void fireError(java.lang.String description)
          Convenience method to fire error type DebugEvent's on registered handlers.
protected  void fireLoadingProgress(double progress)
          Convenience method to fire LoadingProgressEvent's on registered handlers.
protected  void fireMediaInfoAvailable(MediaInfo info)
          Convenience method to fire MediaInfoEvent's on registered handlers.
protected  void firePlayerStateEvent(PlayerStateEvent.State state)
          Convenience method to fire PlayerStateEvent's on registered handlers.
protected  void firePlayStateEvent(PlayStateEvent.State state, int itemIndex)
          Convenience method to fire PlayStateEvent's on registered handlers.
 int getLoopCount()
          Returns the number of times this player repeats playback before stopping.
abstract  long getMediaDuration()
          Returns the duration of the loaded media in milliseconds.
abstract  double getPlayPosition()
          Gets the current position in the media that is being played.
 double getRate()
          Returns the current playback rate
 RepeatMode getRepeatMode()
          Returns the current playback repeat mode
 int getVideoHeight()
          Returns the height of the current media
 int getVideoWidth()
          Returns the width of the current media
abstract  double getVolume()
          Gets the volume ranging from 0 (silent) to 1 (full volume).
protected  PlayerProviderFactory getWidgetFactory(java.lang.String providerName)
          Returns a reference to the PlayerProviderFactory implementation with the specified providerName
 boolean isControllerVisible()
          Checks whether the player controls are visible.
protected static boolean isPlayerOnPage(java.lang.String playerId)
          Checks if the player plugin with the specified playerId is attached to the browsers' DOM
 boolean isResizeToVideoSize()
          Checks if player is set to adjust its size to match the dimensions of a video.
abstract  void loadMedia(java.lang.String mediaURL)
          Loads the media at the specified URL into the player.
abstract  void pauseMedia()
          Pause the media playback
abstract  void playMedia()
          Plays the media loaded into the player.
protected  void removeFromPlayerReadyCommandQueue(java.lang.String key)
          Removes a queued command with the specified key from this players' command queue.
 void setConfigParameter(ConfigParameter param, java.lang.Number value)
          Sets the specified player parameter to the specified value IF AND ONLY IF the parameter is applicable on the player
 void setConfigParameter(ConfigParameter param, java.lang.String value)
          Sets the specified player parameter to the specified value IF AND ONLY IF the parameter is applicable on the player
<T extends ConfigValue>
void
setConfigParameter(ConfigParameter param, T value)
          Sets the specified player parameter to the specified value IF AND ONLY IF the parameter is applicable on the player
 void setControllerVisible(boolean show)
          Displays or hides the player controls.
 void setLoopCount(int loop)
          Sets the number of times the current media file should repeat playback before stopping.
abstract  void setPlayPosition(double position)
          Sets the playback position of the current media
 void setRate(double rate)
          Sets the playback rate.
 void setRepeatMode(RepeatMode mode)
          Puts the player in the specified repeat mode.
 void setResizeToVideoSize(boolean resize)
          If the current media is a video, sets the player to adjust its size to match the dimensions of the video
abstract  void setVolume(double volume)
          Sets the volume.
 void showLogger(boolean show)
          Displays or hides the players' logger widget.
abstract  void stopMedia()
          Stops the media playback.
 
Methods inherited from class com.google.gwt.user.client.ui.Composite
getWidget, initWidget, isAttached, onAttach, onBrowserEvent, onDetach, setWidget
 
Methods inherited from class com.google.gwt.user.client.ui.Widget
addAttachHandler, addDomHandler, addHandler, asWidget, asWidgetOrNull, createHandlerManager, delegateEvent, doAttachChildren, doDetachChildren, fireEvent, getHandlerCount, getLayoutData, getParent, isOrWasAttached, onLoad, onUnload, removeFromParent, setLayoutData, sinkEvents
 
Methods inherited from class com.google.gwt.user.client.ui.UIObject
addStyleDependentName, addStyleName, ensureDebugId, ensureDebugId, ensureDebugId, getAbsoluteLeft, getAbsoluteTop, getElement, getOffsetHeight, getOffsetWidth, getStyleElement, getStyleName, getStyleName, getStylePrimaryName, getStylePrimaryName, getTitle, isVisible, isVisible, onEnsureDebugId, removeStyleDependentName, removeStyleName, setElement, setElement, setHeight, setPixelSize, setSize, setStyleDependentName, setStyleName, setStyleName, setStyleName, setStyleName, setStylePrimaryName, setStylePrimaryName, setTitle, setVisible, setVisible, setWidth, toString, unsinkEvents
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface com.google.gwt.event.shared.HasHandlers
fireEvent
 

Constructor Detail

AbstractMediaPlayer

public AbstractMediaPlayer()
Constructor method.

Method Detail

loadMedia

public abstract void loadMedia(java.lang.String mediaURL)
                        throws LoadException
Loads the media at the specified URL into the player.

In respect of the same domain policy of some plugins, the URL should point to a destination on the same domain where the application is hosted.

Parameters:
mediaURL - the URL of the media to load into the player.
Throws:
LoadException - if an error occurs while loading the media
java.lang.IllegalStateException - if the player is not available, this is the case if the player is not attached to the DOM.

playMedia

public abstract void playMedia()
                        throws PlayException
Plays the media loaded into the player.

Throws:
PlayException - if an error occurs during media playback.
java.lang.IllegalStateException - if the player is not available, this is the case if the player is not attached to the DOM.

stopMedia

public abstract void stopMedia()
Stops the media playback.

Throws:
java.lang.IllegalStateException - if the player is not available, this is the case if the player is not attached to the DOM.

pauseMedia

public abstract void pauseMedia()
Pause the media playback

Throws:
java.lang.IllegalStateException - if the player is not available, this is the case if the player is not attached to the DOM.

getMediaDuration

public abstract long getMediaDuration()
Returns the duration of the loaded media in milliseconds. An IllegalStateException is thrown is the player is not available

Returns:
the duration of the loaded media in milliseconds.
Throws:
java.lang.IllegalStateException - if the player is not available, this is the case if the player is not attached to the DOM.

getPlayPosition

public abstract double getPlayPosition()
Gets the current position in the media that is being played.

Returns:
the current position of the media being played.
Throws:
java.lang.IllegalStateException - if the player is not available, this is the case if the player is not attached to the DOM.

setPlayPosition

public abstract void setPlayPosition(double position)
Sets the playback position of the current media

Parameters:
position - the new position from where to start playback
Throws:
java.lang.IllegalStateException - if the player is not available, this is the case if the player is not attached to the DOM.

getVolume

public abstract double getVolume()
Gets the volume ranging from 0 (silent) to 1 (full volume).

Returns:
volume.
Throws:
java.lang.IllegalStateException - if the player is not available, this is the case if the player is not attached to the DOM.

setVolume

public abstract void setVolume(double volume)
Sets the volume.

Parameters:
volume - 0 (silent) to 1 (full volume).
Throws:
java.lang.IllegalStateException - if the player is not available, this is the case if the player is not attached to the DOM.

firePlayStateEvent

protected final void firePlayStateEvent(PlayStateEvent.State state,
                                        int itemIndex)
Convenience method to fire PlayStateEvent's on registered handlers.

Parameters:
state - the state of the player
See Also:
PlayStateEvent

firePlayerStateEvent

protected final void firePlayerStateEvent(PlayerStateEvent.State state)
Convenience method to fire PlayerStateEvent's on registered handlers.

Parameters:
state - the state of the player
See Also:
PlayerStateEvent

fireError

protected final void fireError(java.lang.String description)
Convenience method to fire error type DebugEvent's on registered handlers.

Parameters:
description - the description of the error
See Also:
DebugEvent

fireDebug

protected final void fireDebug(java.lang.String message)
Convenience method to fire DebugEvent's with informational messages on registered handlers.

Parameters:
message - the message
See Also:
DebugEvent

fireLoadingProgress

protected final void fireLoadingProgress(double progress)
Convenience method to fire LoadingProgressEvent's on registered handlers.

Parameters:
progress - the progress of the loading operation
See Also:
LoadingProgressEvent

fireMediaInfoAvailable

protected final void fireMediaInfoAvailable(MediaInfo info)
Convenience method to fire MediaInfoEvent's on registered handlers.

Parameters:
info - the metadata of the loaded media
See Also:
MediaInfoEvent

showLogger

public void showLogger(boolean show)
Displays or hides the players' logger widget. The logger widget logs debug messages which can be useful during development.

Parameters:
show - true to make the logger widget visible, false otherwise.
Since:
0.6
See Also:
Logger

setControllerVisible

public void setControllerVisible(boolean show)
Displays or hides the player controls. This implementation does nothing. Subclasses that permit showing/hiding of controls should override this method and implement accordingly.

Parameters:
show - true to make the player controls visible, false otherwise.
Since:
0.6

isControllerVisible

public boolean isControllerVisible()
Checks whether the player controls are visible. This implementation return true. Subclasses that permit showing/hiding of controls should override this method and implement accordingly.

Returns:
true if player controls are visible, false otherwise.
Since:
0.6

setLoopCount

public void setLoopCount(int loop)
Sets the number of times the current media file should repeat playback before stopping. This implementation does nothing, subclasses should override and implement accordingly.

NB: As of version 1.2, the behaviour of this property depends on the setRepeatMode(RepeatMode) property

Parameters:
loop - number of times to repeat playback. A negative value makes playback repeat forever!.
Since:
0.6

getLoopCount

public int getLoopCount()
Returns the number of times this player repeats playback before stopping. This implementation returns 0, subclasses should override and implement accordingly.

Returns:
the number of times this player will repeat playback before stopping.
Since:
0.6

addToPlayerReadyCommandQueue

protected final void addToPlayerReadyCommandQueue(java.lang.String key,
                                                  com.google.gwt.user.client.Command command)
Adds the specified command to this players' command queue. The command queue is a hash-map of commands that are schedule for execution as soon as the underlying plugin is ready for javascript interaction.

The execution of the commands is tied to the Ready state of the PlayerState event of the underlying plugin. All scheduled commands are executed exactly once.

Note: If multiple commands use the same key, only the last command is executed.

Parameters:
key - key with which the specified command is to be associated
command - the command to execute when the player plugin is ready for interaction
Since:
1.0

removeFromPlayerReadyCommandQueue

protected final void removeFromPlayerReadyCommandQueue(java.lang.String key)
Removes a queued command with the specified key from this players' command queue.

Parameters:
key - key whose command is to be removed
Since:
1.0
See Also:
addToPlayerReadyCommandQueue(java.lang.String, com.google.gwt.user.client.Command)

addLoadingProgressHandler

public final com.google.gwt.event.shared.HandlerRegistration addLoadingProgressHandler(LoadingProgressHandler handler)
Adds the specified loading progress handler to the player

Specified by:
addLoadingProgressHandler in interface HasMediaProgressHandlers
Parameters:
handler - the handler
Returns:
the HandlerRegistration used to remove the handler
Since:
1.0
See Also:
LoadingProgressHandler

addMediaInfoHandler

public final com.google.gwt.event.shared.HandlerRegistration addMediaInfoHandler(MediaInfoHandler handler)
Adds the specified MediaInfo handler to the player

Specified by:
addMediaInfoHandler in interface HasMediaMessageHandlers
Parameters:
handler - the handler
Returns:
the HandlerRegistration used to remove the handler
Since:
1.0
See Also:
MediaInfoHandler

addPlayStateHandler

public final com.google.gwt.event.shared.HandlerRegistration addPlayStateHandler(PlayStateHandler handler)
Adds the specified play-state handler to the player

Specified by:
addPlayStateHandler in interface HasPlayStateHandlers
Parameters:
handler - the handler
Returns:
the HandlerRegistration used to remove the handler
Since:
1.0
See Also:
PlayStateHandler

addPlayerStateHandler

public final com.google.gwt.event.shared.HandlerRegistration addPlayerStateHandler(PlayerStateHandler handler)
Adds the specified player-state handler to the player

Specified by:
addPlayerStateHandler in interface HasPlayStateHandlers
Parameters:
handler - the handler
Returns:
the HandlerRegistration used to remove the handler
Since:
1.0
See Also:
PlayerStateHandler

addDebugHandler

public final com.google.gwt.event.shared.HandlerRegistration addDebugHandler(DebugHandler handler)
Adds the specified debug handler to the player

Specified by:
addDebugHandler in interface HasMediaMessageHandlers
Parameters:
handler - the handler
Returns:
the HandlerRegistration used to remove the handler
Since:
1.0
See Also:
DebugHandler

setResizeToVideoSize

public void setResizeToVideoSize(boolean resize)
If the current media is a video, sets the player to adjust its size to match the dimensions of the video

Parameters:
resize - true if player should adjust its size, false otherwise
Since:
1.0

isResizeToVideoSize

public boolean isResizeToVideoSize()
Checks if player is set to adjust its size to match the dimensions of a video.

Returns:
true if player adjusts its size, false otherwise
Since:
1.0

getVideoHeight

public int getVideoHeight()
Returns the height of the current media

Returns:
the height in pixels
Since:
1.0

getVideoWidth

public int getVideoWidth()
Returns the width of the current media

Returns:
the width in pixels
Since:
1.0

isPlayerOnPage

protected static final boolean isPlayerOnPage(java.lang.String playerId)
Checks if the player plugin with the specified playerId is attached to the browsers' DOM

This method is provided for the convenience of player implementation classes.

Parameters:
playerId - the object ID of the player plugin
Returns:
true if player plugin is attached, false otherwise.
Since:
1.0

setConfigParameter

public <T extends ConfigValue> void setConfigParameter(ConfigParameter param,
                                                       T value)
Sets the specified player parameter to the specified value IF AND ONLY IF the parameter is applicable on the player

Note: The parameter-value pairs are applied as HTML param tags on the underlying player plugin, therefore this method should be called before adding this player to a panel otherwise the method call will have no effect.

Overriding in a subclass

This method should be called first by any subclass that overrides it. This implementation checks if the specified value is a valid type for the specified parameter.

Type Parameters:
T - the paramter value type
Parameters:
param - the configuration parameter
value - the parameter value
Throws:
java.lang.IllegalArgumentException - if value is not of the required type
Since:
1.1

setConfigParameter

public void setConfigParameter(ConfigParameter param,
                               java.lang.Number value)
Sets the specified player parameter to the specified value IF AND ONLY IF the parameter is applicable on the player

Overriding in a subclass

This method should be called first by any subclass that overrides it. This implementation checks if the specified value is a valid type for the specified parameter.

Parameters:
param - the configuration parameter
value - the numeric value
Throws:
java.lang.IllegalArgumentException - if param is not useable with a number
Since:
1.2
See Also:
setConfigParameter(ConfigParameter, ConfigValue)

setConfigParameter

public void setConfigParameter(ConfigParameter param,
                               java.lang.String value)
Sets the specified player parameter to the specified value IF AND ONLY IF the parameter is applicable on the player

Overriding in a subclass

This method should be called first by any subclass that overrides it. This implementation checks if the specified value is a valid type for the specified parameter.

Parameters:
param - the configuration parameter
value - the String value
Throws:
java.lang.IllegalArgumentException - if param is not useable with a String
Since:
1.2.1
See Also:
setConfigParameter(ConfigParameter, ConfigValue)

setRate

public void setRate(double rate)
Sets the playback rate.

If this player is not available on the panel, this method call is added to the command-queue for later execution.

Parameters:
rate - the playback rate. A rate of 1 implies normal playback rate, fractional values are slow motion, and values greater than one are fast-forward
Since:
1.1

getRate

public double getRate()
Returns the current playback rate

Returns:
the playback rate
Since:
1.1
See Also:
setRate(double)

addMouseMoveHandler

public com.google.gwt.event.shared.HandlerRegistration addMouseMoveHandler(com.google.gwt.event.dom.client.MouseMoveHandler handler)
Adds the mouse move handler to the player

Specified by:
addMouseMoveHandler in interface com.google.gwt.event.dom.client.HasMouseMoveHandlers
Parameters:
handler - the handler
Returns:
the HandlerRegistration used to remove the handler
Since:
1.1

addMouseDownHandler

public com.google.gwt.event.shared.HandlerRegistration addMouseDownHandler(com.google.gwt.event.dom.client.MouseDownHandler handler)
Adds the mouse down handler to the player

Specified by:
addMouseDownHandler in interface com.google.gwt.event.dom.client.HasMouseDownHandlers
Parameters:
handler - the handler
Returns:
the HandlerRegistration used to remove the handler
Since:
1.1

addMouseUpHandler

public com.google.gwt.event.shared.HandlerRegistration addMouseUpHandler(com.google.gwt.event.dom.client.MouseUpHandler handler)
Adds the mouse up handler to the player

Specified by:
addMouseUpHandler in interface com.google.gwt.event.dom.client.HasMouseUpHandlers
Parameters:
handler - the handler
Returns:
the HandlerRegistration used to remove the handler
Since:
1.1

addKeyDownHandler

public com.google.gwt.event.shared.HandlerRegistration addKeyDownHandler(com.google.gwt.event.dom.client.KeyDownHandler handler)
Adds the key down handler to the player

Specified by:
addKeyDownHandler in interface com.google.gwt.event.dom.client.HasKeyDownHandlers
Parameters:
handler - the handler
Returns:
the HandlerRegistration used to remove the handler
Since:
1.1

addKeyUpHandler

public com.google.gwt.event.shared.HandlerRegistration addKeyUpHandler(com.google.gwt.event.dom.client.KeyUpHandler handler)
Adds the key up handler to the player

Specified by:
addKeyUpHandler in interface com.google.gwt.event.dom.client.HasKeyUpHandlers
Parameters:
handler - the handler
Returns:
the HandlerRegistration used to remove the handler
Since:
1.1

addKeyPressHandler

public com.google.gwt.event.shared.HandlerRegistration addKeyPressHandler(com.google.gwt.event.dom.client.KeyPressHandler handler)
Adds the key press handler to the player

Specified by:
addKeyPressHandler in interface com.google.gwt.event.dom.client.HasKeyPressHandlers
Parameters:
handler - the handler
Returns:
the HandlerRegistration used to remove the handler
Since:
1.1

setRepeatMode

public void setRepeatMode(RepeatMode mode)
Puts the player in the specified repeat mode.

The effect of the specified mode depends on the setLoopCount(int) property as shown in the table:

Value of loopCount Value of repeatMode What it means?
Any value < 0 Sets repeatMode to RepeatMode.REPEAT_ALL Playlist is repeated continously
1 RepeatMode.REPEAT_OFF Entire playlist is played only once
RepeatMode.REPEAT_ONE The current playlist entry is repeated continously
RepeatMode.REPEAT_ALL Entire playlist is repeated continously
Any value > 1 RepeatMode.REPEAT_OFF The loopCount property is ignored, and the entire playlist is played only once
RepeatMode.REPEAT_ONE Player repeats each playlist entry for the number of times specified by loopCount and moves on the next until all entries are played and stops
RepeatMode.REPEAT_ALL Player repeats entire playlist for the number of times specified by loopCount and stops

Parameters:
mode - the new repeat mode
Since:
1.2
See Also:
RepeatMode

getRepeatMode

public RepeatMode getRepeatMode()
Returns the current playback repeat mode

Returns:
repeat mode
Since:
1.2
See Also:
RepeatMode

getWidgetFactory

protected final PlayerProviderFactory getWidgetFactory(java.lang.String providerName)
Returns a reference to the PlayerProviderFactory implementation with the specified providerName

This method is provided for the convenience of player implementation classes.

Parameters:
providerName - the provider name
Returns:
PlayerProviderFactory implementation with the specified providerName or null if no such provider exists.
Since:
1.3


Copyright © 2009-2011. All Rights Reserved.