com.bramosystems.oss.player.youtube.client
Class YouTubePlayer

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
                  extended by com.bramosystems.oss.player.youtube.client.YouTubePlayer
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:
ChromelessPlayer

public class YouTubePlayer
extends AbstractMediaPlayer

Widget to embed YouTube video

Usage Example

 SimplePanel panel = new SimplePanel();   // create panel to hold the player
 Widget player = null;
 try {
      // create the player
      player = new YouTubePlayer("http://www.youtube.com/v/VIDEO_ID&fs=1", "100%", "350px");
 } catch(PluginVersionException e) {
      // catch plugin version exception and alert user to download plugin first.
      // An option is to use the utility method in PlayerUtil class.
      player = PlayerUtil.getMissingPluginNotice(e.getPlugin());
 } catch(PluginNotFoundException e) {
      // catch PluginNotFoundException and tell user to download plugin, possibly providing
      // a link to the plugin download page.
      player = new HTML(".. another kind of message telling the user to download plugin..");
 }

 panel.setWidget(player); // add player to panel.
 

Since:
1.1
Author:
Sikirulai 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
protected  java.lang.String _height
           
protected  java.lang.String _vURL
           
protected  java.lang.String _width
           
protected  com.bramosystems.oss.player.youtube.client.impl.YouTubePlayerImpl impl
           
protected  java.lang.String playerId
           
 
Fields inherited from class com.google.gwt.user.client.ui.UIObject
DEBUG_ID_PREFIX
 
Constructor Summary
YouTubePlayer(java.lang.String videoURL, PlayerParameters playerParameters, java.lang.String width, java.lang.String height)
          Constructs YouTubePlayer with the specified height and width to playback video located at videoURL using the specified playerParameters
YouTubePlayer(java.lang.String videoURL, java.lang.String width, java.lang.String height)
          Constructs YouTubePlayer with the specified height and width to playback video located at videoURL
 
Method Summary
 com.google.gwt.event.shared.HandlerRegistration addPlaybackQualityChangeHandler(PlaybackQualityChangeHandler handler)
          Adds a PlaybackQualityChangeHandler handler to the player
 java.util.ArrayList<PlaybackQuality> getAvailableQualityLevels()
          Returns the list of quality formats in which the current video is available.
 int getLoopCount()
          Returns the number of times this player repeats playback before stopping.
 long getMediaDuration()
          Returns the duration of the loaded media in milliseconds.
protected  java.lang.String getNormalizedVideoAppURL(java.lang.String videoURL, PlayerParameters playerParameters)
          Returns the normalized URL of the video.
 PlaybackQuality getPlaybackQuality()
          Retrieves the playback quality of the current video.
 double getPlayPosition()
          Gets the current position in the media that is being played.
 RepeatMode getRepeatMode()
          Returns the current playback repeat mode
 double getVolume()
          Gets the volume ranging from 0 (silent) to 1 (full volume).
 boolean isControllerVisible()
          Checks whether the player controls are visible.
 void loadMedia(java.lang.String mediaURL)
          Loads the media at the specified URL into the player.
protected  void onLoad()
           
protected  void onUnload()
           
protected  java.lang.String paramsToString(PlayerParameters playerParameters)
          Converts the PlayerParameters object into YouTube™ video URL parameters.
protected  void parseURLParams(java.lang.String videoURL, PlayerParameters playerParameters)
          Puts all URL parameters that may be present in the videoURL into the playerParameters object.
 void pauseMedia()
          Pause the media playback
protected  void playerInit()
          Called when player initialization is completed.
 void playMedia()
          Plays the media loaded into 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 setLoopCount(int loop)
          Sets the number of times the current media file should repeat playback before stopping.
 void setPlaybackQuality(PlaybackQuality suggestedQuality)
          Sets the suggested video quality for the current video.
 void setPlayPosition(double position)
          Sets the playback position of the current media
 void setRepeatMode(RepeatMode mode)
          Puts the player in the specified repeat mode.
 void setVolume(double volume)
          Sets the volume.
 void showLogger(boolean show)
          Displays or hides the players' logger widget.
 void stopMedia()
          Stops the media playback.
 
Methods inherited from class com.bramosystems.oss.player.core.client.AbstractMediaPlayer
addDebugHandler, addKeyDownHandler, addKeyPressHandler, addKeyUpHandler, addLoadingProgressHandler, addMediaInfoHandler, addMouseDownHandler, addMouseMoveHandler, addMouseUpHandler, addPlayerStateHandler, addPlayStateHandler, addToPlayerReadyCommandQueue, fireDebug, fireError, fireLoadingProgress, fireMediaInfoAvailable, firePlayerStateEvent, firePlayStateEvent, getRate, getVideoHeight, getVideoWidth, getWidgetFactory, isPlayerOnPage, isResizeToVideoSize, removeFromPlayerReadyCommandQueue, setConfigParameter, setConfigParameter, setControllerVisible, setRate, setResizeToVideoSize
 
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, 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
 

Field Detail

impl

protected com.bramosystems.oss.player.youtube.client.impl.YouTubePlayerImpl impl

playerId

protected java.lang.String playerId

_width

protected java.lang.String _width

_height

protected java.lang.String _height

_vURL

protected java.lang.String _vURL
Constructor Detail

YouTubePlayer

public YouTubePlayer(java.lang.String videoURL,
                     java.lang.String width,
                     java.lang.String height)
              throws PluginNotFoundException,
                     PluginVersionException
Constructs YouTubePlayer with the specified height and width to playback video located at videoURL

height and width are specified as CSS units.

Parameters:
videoURL - the URL of the video
width - the width of the player
height - the height of the player
Throws:
PluginNotFoundException - if the required Flash player plugin is not found
PluginVersionException - if Flash player version 8 and above is not found
java.lang.NullPointerException - if either videoURL, height or width is null

YouTubePlayer

public YouTubePlayer(java.lang.String videoURL,
                     PlayerParameters playerParameters,
                     java.lang.String width,
                     java.lang.String height)
              throws PluginNotFoundException,
                     PluginVersionException
Constructs YouTubePlayer with the specified height and width to playback video located at videoURL using the specified playerParameters

height and width are specified as CSS units.

Parameters:
videoURL - the URL of the video
playerParameters - the parameters of the player
width - the width of the player
height - the height of the player
Throws:
PluginNotFoundException - if the required Flash player plugin is not found
PluginVersionException - if Flash player version 8 and above is not found
java.lang.NullPointerException - if either videoURL, height or width is null
Method Detail

onLoad

protected void onLoad()
Overrides:
onLoad in class com.google.gwt.user.client.ui.Widget

onUnload

protected void onUnload()
Overrides:
onUnload in class com.google.gwt.user.client.ui.Widget

getNormalizedVideoAppURL

protected java.lang.String getNormalizedVideoAppURL(java.lang.String videoURL,
                                                    PlayerParameters playerParameters)
Returns the normalized URL of the video.

This method is called by the player Constructors. It adjusts the parameters that may be present in the videoURL and playerParameters (possibly overriding some) to match the requirements of this players' internals.

Parameters:
videoURL - the URL of the YouTube™ video
playerParameters - the parameters of the video
Returns:
the normalized URL of the video

playerInit

protected void playerInit()
Called when player initialization is completed.


parseURLParams

protected final void parseURLParams(java.lang.String videoURL,
                                    PlayerParameters playerParameters)
Puts all URL parameters that may be present in the videoURL into the playerParameters object.

Note: when this method returns, all parameters present in videoURL would have been removed. For example:

If videoURL before method call is http://www.youtube.com/v/VIDEO_ID¶mName=value, then videoURL after method call is http://www.youtube.com/v/VIDEO_ID.

Parameters:
videoURL - the URL of the YouTube™ video
playerParameters - the parameters of the video

paramsToString

protected final java.lang.String paramsToString(PlayerParameters playerParameters)
Converts the PlayerParameters object into YouTube™ video URL parameters.

Parameters:
playerParameters - the player parameters
Returns:
the parameters in YouTube™ video URL format

loadMedia

public void loadMedia(java.lang.String mediaURL)
               throws LoadException
Description copied from class: AbstractMediaPlayer
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.

Specified by:
loadMedia in class AbstractMediaPlayer
Parameters:
mediaURL - the URL of the media to load into the player.
Throws:
LoadException - if an error occurs while loading the media

playMedia

public void playMedia()
               throws PlayException
Description copied from class: AbstractMediaPlayer
Plays the media loaded into the player.

Specified by:
playMedia in class AbstractMediaPlayer
Throws:
PlayException - if an error occurs during media playback.

stopMedia

public void stopMedia()
Description copied from class: AbstractMediaPlayer
Stops the media playback.

Specified by:
stopMedia in class AbstractMediaPlayer

pauseMedia

public void pauseMedia()
Description copied from class: AbstractMediaPlayer
Pause the media playback

Specified by:
pauseMedia in class AbstractMediaPlayer

getMediaDuration

public long getMediaDuration()
Description copied from class: AbstractMediaPlayer
Returns the duration of the loaded media in milliseconds. An IllegalStateException is thrown is the player is not available

Specified by:
getMediaDuration in class AbstractMediaPlayer
Returns:
the duration of the loaded media in milliseconds.

getPlayPosition

public double getPlayPosition()
Description copied from class: AbstractMediaPlayer
Gets the current position in the media that is being played.

Specified by:
getPlayPosition in class AbstractMediaPlayer
Returns:
the current position of the media being played.

setPlayPosition

public void setPlayPosition(double position)
Description copied from class: AbstractMediaPlayer
Sets the playback position of the current media

Specified by:
setPlayPosition in class AbstractMediaPlayer
Parameters:
position - the new position from where to start playback

getVolume

public double getVolume()
Description copied from class: AbstractMediaPlayer
Gets the volume ranging from 0 (silent) to 1 (full volume).

Specified by:
getVolume in class AbstractMediaPlayer
Returns:
volume.

setVolume

public void setVolume(double volume)
Description copied from class: AbstractMediaPlayer
Sets the volume.

Specified by:
setVolume in class AbstractMediaPlayer
Parameters:
volume - 0 (silent) to 1 (full volume).

getLoopCount

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

Overrides:
getLoopCount in class AbstractMediaPlayer
Returns:
the number of times this player will repeat playback before stopping.

setLoopCount

public void setLoopCount(int loop)
Description copied from class: AbstractMediaPlayer
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 AbstractMediaPlayer.setRepeatMode(RepeatMode) property

Overrides:
setLoopCount in class AbstractMediaPlayer
Parameters:
loop - number of times to repeat playback. A negative value makes playback repeat forever!.

getRepeatMode

public RepeatMode getRepeatMode()
Description copied from class: AbstractMediaPlayer
Returns the current playback repeat mode

Overrides:
getRepeatMode in class AbstractMediaPlayer
Returns:
repeat mode
See Also:
RepeatMode

setRepeatMode

public void setRepeatMode(RepeatMode mode)
Description copied from class: AbstractMediaPlayer
Puts the player in the specified repeat mode.

The effect of the specified mode depends on the AbstractMediaPlayer.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

Overrides:
setRepeatMode in class AbstractMediaPlayer
Parameters:
mode - the new repeat mode
See Also:
RepeatMode

isControllerVisible

public boolean isControllerVisible()
Checks whether the player controls are visible. This implementation always return true.

Overrides:
isControllerVisible in class AbstractMediaPlayer
Returns:
true if player controls are visible, false otherwise.

showLogger

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

Overrides:
showLogger in class AbstractMediaPlayer
Parameters:
show - true to make the logger widget visible, false otherwise.
See Also:
Logger

setPlaybackQuality

public void setPlaybackQuality(PlaybackQuality suggestedQuality)
Sets the suggested video quality for the current video. This method causes the video to reload at its current position in the new quality.

Note: Calling this method does not guarantee that the playback quality will actually change. If the playback quality does change, it will only change for the video being played and the PlaybackQualityChangeEvent event will be fired.

If suggestedQuality is not available for the current video, then the quality will be set to the next lowest level that is available. That is, if suggestedQuality is PlaybackQuality.hd720 and that is unavailable, then the playback quality will be set to PlaybackQuality.large if that quality level is available.

Parameters:
suggestedQuality - the suggested video quality for the current video

getPlaybackQuality

public PlaybackQuality getPlaybackQuality()
                                   throws java.lang.IllegalStateException
Retrieves the playback quality of the current video.

Returns:
the playback quality of the current video
Throws:
java.lang.IllegalStateException - if no video is loaded in the player

getAvailableQualityLevels

public java.util.ArrayList<PlaybackQuality> getAvailableQualityLevels()
Returns the list of quality formats in which the current video is available.

An empty list is returned if no video is loaded.

Returns:
a list of quality formats available for the current video

addPlaybackQualityChangeHandler

public com.google.gwt.event.shared.HandlerRegistration addPlaybackQualityChangeHandler(PlaybackQualityChangeHandler handler)
Adds a PlaybackQualityChangeHandler handler to the player

Parameters:
handler - handler for the PlaybackQualityChangeEvent event
Returns:
HandlerRegistration used to remove the handler

setConfigParameter

public <T extends ConfigValue> void setConfigParameter(ConfigParameter param,
                                                       T value)
Description copied from class: AbstractMediaPlayer
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.

Overrides:
setConfigParameter in class AbstractMediaPlayer
Type Parameters:
T - the paramter value type
Parameters:
param - the configuration parameter
value - the parameter value


Copyright © 2009-2011. All Rights Reserved.