YouTube Player Provider

The YouTube Player Provider provides widgets to embed YouTube videos to GWT applications.

GWT Module Inheritance / Provider Name

Add the following line to your GWT XML application module file to include the player provider in your application:

<inherits name="com.bramosystems.oss.player.youtube.YouTube" />

The provider is registered with the API as "bst.youtube"

Version Dependency Matrix

The following table lists the minimum version of the package dependencies required by the player provider:

YouTube Player Provider version BST Player API version GWT version
2.0 2.0.2 2.2

Provided player widgets

The following table lists all player widgets available with the player provider package, the supported plugin and the minimum plugin version required on the browser.

Player Widget Provider Name Media Plugin Minimum plugin version
YouTubePlayer YouTube Flash® Player plugin 10.0
ChromelessPlayer Chromeless Flash® Player plugin 10.0
YouTubeIPlayer IYouTube HTML5 Browser -

All the player widgets class resides in the com.bramosystems.oss.player.youtube.client package.

Working with the player widgets

The YouTubePlayer widget wraps the basic YouTube video player and can be used as follows:

SimplePanel panel = new SimplePanel();   // create panel to hold the player
AbstractMediaPlayer player = null;
try {
    // create the player, specifing URL of media
    player = new YouTubePlayer("video-id", "width", "height");
    panel.setWidget(player); // add player to panel.
} catch(PluginVersionException e) {
    // required Flash plugin version is not available,
    // alert user possibly providing a link to the plugin download page.
    panel.setWidget(new HTML(".. some nice message telling the " +
        "user to download plugin first .."));
} catch(PluginNotFoundException e) {
    // required Flash plugin not found, display a friendly notice.
    panel.setWidget(PlayerUtil.getMissingPluginNotice(e.getPlugin()));
}

The ChromelessPlayer widget provides the YouTube player without native player controls. This is useful if you want to make your own player controls.

The following is an example:

SimplePanel panel = new SimplePanel();   // create panel to hold the player
AbstractMediaPlayer player = null;
try {
    // create the player, specifing URL of media
    player = new ChromelessPlayer("video-id", "100%", "350px");
    CustomPlayerControl cpc = new CustomPlayerControl(player);

    FlowPanel fp = new FlowPanel();
    fp.add(player);
    fp.add(cpc);
    panel.setWidget(fp); // add player and custom control to panel.
} catch(PluginVersionException e) {
    // required Flash plugin version is not available,
    // alert user possibly providing a link to the plugin download page.
    panel.setWidget(new HTML(".. some nice message telling the " +
        "user to download plugin first .."));
} catch(PluginNotFoundException e) {
    // required Flash plugin not found, display a friendly notice.
    panel.setWidget(PlayerUtil.getMissingPluginNotice(e.getPlugin()));
}

The YouTubeIPlayer widget provides the YouTube player using the latest IFrame API which provides improved support for both desktop and mobile devices. However, this will only work on HTML5-compliant environments.

The following is an example:

SimplePanel panel = new SimplePanel();   // create panel to hold the player
AbstractMediaPlayer player = null;
try {
    // create the player, specifing URL of media
    player = new YouTubeIPlayer("video-id", "100%", "350px");
    panel.setWidget(player); // add player to panel.
} catch(PluginVersionException e) {
    // not thrown for now.  Only provided for Base API support...
} catch(PluginNotFoundException e) {
    // browser is not HTML5 compliant ..
    panel.setWidget(PlayerUtil.getMissingPluginNotice(e.getPlugin()));
}

All the widgets can also be used with the Base API utility methods as follows:

SimplePanel panel = new SimplePanel();   // create panel to hold the player
AbstractMediaPlayer player = null;
try {
    // retrieve the basic information about the YouTubeIPlayer as registered with the API
    // using the provider name and the player name
    PlayerInfo pi = PlayerUtil.getPlayerInfo("bst.youtube", "IYouTube");

    // create the player, using the PlayerInfo object and specifing URL of media
    player = PlayerUtil.getPlayer(pi, "youtube-video-id", false, 
        "width", "height");
    panel.setWidget(player); // add player to panel.
} catch(PluginVersionException e) {
    // required plugin version is not available, alert user
    panel.setWidget(PlayerUtil.getMissingPluginNotice(e.getPlugin(), 
            e.getRequiredVersion()));
} catch(PluginNotFoundException e) {
    // catch PluginNotFoundException and display a friendly notice.
    panel.setWidget(PlayerUtil.getMissingPluginNotice(e.getPlugin));
}