I'm developing a GWT application. I need to embed a YouTube video in my application.
I've tried BST player API but I wasn't successful in bringing up the video on the player. I've downloaded BSTPlayer.jar
and added it to my buildpath, then inherited the following jars in gwtapp.gwt.xml
:
**inherits name ='com.bramosystems.oss.player.core.Core'**
**inherits name ='com.bramosystems.oss.player.youtube.YouTube'**
Then I tried the example given on BST page:
simplePanel = new SimplePanel();
add(simplePanel);
simplePanel.setSize("", "");
try {
// create the player, specifing URL of media
player = new ChromelessPlayer("http://www.youtube.com/watch?v=O3CZFfyed3M", "80%", "350px");
CustomPlayerControl cpc = new CustomPlayerControl(player);
FlowPanel fp = new FlowPanel();
fp.add(player);
fp.add(cpc);
simplePanel.setWidget(fp); // add player and custom control to panel.
} catch (PluginVersionException e) {
// required Flash plugin version is not available,
// alert user poss开发者_如何学运维ibly providing a link to the plugin download page.
simplePanel.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.
simplePanel.setWidget(PlayerUtil.getMissingPluginNotice(e.getPlugin()));
}
I could see the panel with the YouTube player but I couldn't see the video loading nor playing. I've tried player.playMedia()
and it was of no help. Any ideas of how to proceed and make the video work?
You probably need to be passing this URL instead:
http://www.youtube.com/v/O3CZFfyed3M
I found a way to embed youtube videos in a GWT vithout using any external library. Integration level is very simple so you can not make any advanced use. Here it is the code fragment of a UIBinder template and its corresponding class:
Using and HTMLPanel put an object element like this:
<g:HTMLPanel>
<object ui:field="videoElement"
type="application/x-shockwave-flash"
width="640" height="480" data="">
</object>
</g:HTMLPanel>
@UIField
ObjectElement videoElement;
[...]
public void displayVideo(String videoId) {
String videoUrl = "http://www.youtube.com/v/".concat(videoId);
videoElement.setData(videoUrl); //change data attribute of object element
String innerHtml = "<param name=\"movie\" value=\""+ videoUrl +"\" />";
//add param element, of course yo can add as many param elements as needed to customize
videoElement.setInnerHTML(innerHtml);
}
To make it work I needed to put this video view inside a Panel and whenever I wanted to view / update the video clear the panel and add the video view again.
Hope this helps
I have created this GWT wrapper on top of YouTubes Iframe api library. Which makes it easier to use YouTube api inside gwt check https://github.com/pandurangpatil/gwt-youtube
精彩评论