使用GWT在html5中播放视频

时间:2012-08-21 07:41:28

标签: html5 gwt

我有游戏(在libgdx中构建) 我使用GWT将其转换为html5

我需要在其中显示电影视频

有什么办法吗?我需要在跨平台上开发我的游戏

3 个答案:

答案 0 :(得分:2)

使用小部件Video。它代表HTML5标记video。但是这个小部件可能无法在所有浏览器上正常运行。

您可以在documentation中了解GWT支持的其他HTML5功能。

答案 1 :(得分:1)

如果您使用此标签,请将此标记添加到您的UIBinder(* .ui.xml)

<g:HTML ui:field="mediaContainer" styleName="mediaPlayer">
 <video autoplay="true" controls="controls" ui:field="mediaPlayer" height="100%" width="100%">
 </video>
</g:HTML>

如果您愿意,请在UiBinder Java Part或Presenter中添加以下代码。我把它添加到我的演示者部分。希望您的UiField对象通过适当的Getter和Setter声明

private Element videoSource = null;
private Element videoPoster = null;

// FOR PLAYING A VIDEO URL THAT THE USER ENTERS
    public void loadTool(String videoUrl) {
        if (videoSource != null) {
            videoSource.removeFromParent();
            videoPoster.removeFromParent();
        }
        videoSource = DOM.createElement("source");
        videoPoster = DOM.createElement("img");
        videoSource.setAttribute("src", videoUrl);
        videoPoster.setAttribute("src",
                MyContants.VIDEO_TEST_IMAGE);
        videoPoster.setAttribute("alt",
                MyContants.VIDEO_TEST_IMAGE_ALT);
        videoSource.getStyle().setVisibility(Visibility.VISIBLE);
        videoPoster.getStyle().setVisibility(Visibility.VISIBLE);
        videoWidget.getMediaPlayer().appendChild(videoSource);
        videoWidget.getMediaPlayer().appendChild(videoPoster);
        videoWidget.getMediaContainer().setVisible(true);
    }

希望这有助于某种方式

答案 2 :(得分:1)

我使用了http://code.google.com/p/gwt-html5-video/downloads/list

显示视频

    VideoWidget videoPlayer = new VideoWidget(true, false, null);

    List<VideoSource> sources = new ArrayList<VideoSource>();
            sources.add(new VideoSource(video, VideoType.MP4));

        videoPlayer.setSources(sources);
        videoPlayer.setPixelSize(960, 640);