2011-08-25 71 views
1

我正在開發GWT應用程序。我需要在我的應用程序中嵌入YouTube視頻。
我試過BST播放器API,但是我沒有成功地提出播放器上的視頻。
我已經下載BST Player.jar,並把它添加到我的構建路徑,然後繼承下面的罐子在gwtapp.gwt.xml在GWT(BST播放器API)中嵌入youtube播放器

**inherits name ='com.bramosystems.oss.player.core.Core'** 
**inherits name ='com.bramosystems.oss.player.youtube.YouTube'** 

然後我試圖BST頁上給出的例子:

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 possibly 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())); 
} 

我能看到與YouTube播放器面板,但我看不到視頻加載或播放。我試過player.playMedia(),這沒有幫助。有關如何繼續並製作視頻的任何想法?

回答

2

你可能需要路過這個網址,而不是:

http://www.youtube.com/v/O3CZFfyed3M 
+0

真棒!謝謝。 – Ashok

+0

這是非常有幫助的,但是我在視頻中看到黑線,任何方式我都可以刪除它..? –

+0

我用這個只有簡單的框架 - 它工作正常,請參考這個 http://stackoverflow.com/questions/14812679/vimeo-embedding-in-gwt –

2

我找到了一種方法嵌入在GWT YouTube視頻vithout使用任何外部庫。集成級別非常簡單,因此您無法進行任何高級使用。這是一個UiBinder的模板的代碼片段和其對應的類:

使用和HTMLPanel把這樣一個對象元素:

<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); 
} 

爲了使它工作,我需要把這個視頻視圖面板內每當我想查看/更新視頻清除面板並再次添加視頻視圖。

希望這有助於

相關問題