Example usage for com.google.gwt.media.client Video createIfSupported

List of usage examples for com.google.gwt.media.client Video createIfSupported

Introduction

In this page you can find the example usage for com.google.gwt.media.client Video createIfSupported.

Prototype

public static Video createIfSupported() 

Source Link

Document

Return a new Video if supported, and null otherwise.

Usage

From source file:com.google.gwt.sample.mobilewebapp.client.desktop.MobileWebAppShellDesktop.java

License:Apache License

/**
 * Show a tutorial video.//w  w  w  . j  a va 2s .  c o  m
 */
private void showTutorial() {
    // Reuse the tutorial dialog if it is already created.
    if (tutoralPopup != null) {
        // Reset the video.
        // TODO(jlabanca): Is cache-control=private making the video non-seekable?
        if (tutorialVideo != null) {
            tutorialVideo.setSrc(tutorialVideo.getCurrentSrc());
        }

        tutoralPopup.center();
        return;
    }

    /*
     * Forward the use to YouTube if video is not supported or if none of the
     * source formats are supported.
     */
    tutorialVideo = Video.createIfSupported();
    if (tutorialVideo == null) {
        Label label = new Label("Click the link below to view the tutoral:");
        Anchor anchor = new Anchor(EXTERNAL_TUTORIAL_URL, EXTERNAL_TUTORIAL_URL);
        anchor.setTarget("_blank");
        FlowPanel panel = new FlowPanel();
        panel.add(label);
        panel.add(anchor);

        tutoralPopup = new PopupPanel(true, false);
        tutoralPopup.setWidget(panel);
        tutoralPopup.setGlassEnabled(true);

        // Hide the popup when the user clicks the link.
        anchor.addClickHandler(new ClickHandler() {
            public void onClick(ClickEvent event) {
                tutoralPopup.hide();
            }
        });

        tutoralPopup.center();
        return;
    }

    // Add the video sources.
    tutorialVideo.addSource("video/tutorial.ogv", VideoElement.TYPE_OGG);
    tutorialVideo.addSource("video/tutorial.mp4", VideoElement.TYPE_MP4);

    // Setup the video player.
    tutorialVideo.setControls(true);
    tutorialVideo.setAutoplay(true);

    // Put the video in a dialog.
    final DialogBox popup = new DialogBox(false, false);
    popup.setText("Tutorial");
    VerticalPanel vPanel = new VerticalPanel();
    vPanel.add(tutorialVideo);
    vPanel.add(new Button("Close", new ClickHandler() {
        public void onClick(ClickEvent event) {
            tutorialVideo.pause();
            popup.hide();
        }
    }));
    popup.setWidget(vPanel);
    tutoralPopup = popup;
    popup.center();
}

From source file:com.webwoz.client.client.WebWOZClient.java

License:Apache License

private void startSession() {

    // define whether client logout should be used or not
    // useClientLogout = true;

    // initialize variables
    processing = "Processing";

    // panels to structure layout
    headPanel = new VerticalPanel();
    titlePanel = new HorizontalPanel();
    contentPanel = new VerticalPanel();
    footPanel = new VerticalPanel();
    loginPanel = new HorizontalPanel();
    asrPanel = new VerticalPanel();
    textPanel = new VerticalPanel();
    audioPanel = new VerticalPanel();
    mmPanel = new VerticalPanel();
    txtInPanel = new HorizontalPanel();

    // labels/*from  w w  w  . j  a  v a2s  .  co  m*/
    userLabel = new Label("User: ");
    pwLabel = new Label("Password: ");
    loginMessage = new Label();

    // text boxes
    userTextBox = new TextBox();
    pwTextBox = new PasswordTextBox();

    // text areas
    textInputTextArea = new TextArea();

    // buttons
    loginButton = new Button("login");
    logoutButton = new Button("logout");
    sendButton = new Button("Send");

    // RPC
    databaseAccessSvc = GWT.create(DatabaseAccess.class);

    currentID = 0;

    audioHTML = Audio.createIfSupported();
    videoHTML = Video.createIfSupported();

    // head
    String header = "<div id='header'></div>";
    headPanel.clear();
    headPanel.add(new HTML(header));

    // title
    String title = "<div id='title'></div>";
    titlePanel.clear();
    titlePanel.add(new HTML(title));

    // build login
    loginPanel.clear();
    loginPanel.add(userLabel);
    loginMessage.setStyleName("loginMessage");
    userLabel.setStyleName("label");
    loginPanel.add(userTextBox);
    userTextBox.setStyleName("text");
    loginPanel.add(pwLabel);
    pwLabel.setStyleName("label");
    loginPanel.add(pwTextBox);
    pwTextBox.setStyleName("text");
    loginPanel.add(loginButton);
    loginButton.setStyleName("buttonLogin");
    // define button but do not add it
    logoutButton.setStyleName("buttonLogin");
    logoutButton.setVisible(false);

    // loginPanel.setStyleName("layout");
    loginPanel.setVisible(true);

    // output panels
    asrPanel.clear();
    asrPanel.setStyleName("asr");
    txtInPanel.clear();
    txtInPanel.setStyleName("txtIn");
    textPanel.clear();
    textPanel.setStyleName("txtOut");
    audioPanel.clear();
    audioPanel.setStyleName("audioOut");
    mmPanel.clear();
    mmPanel.setStyleName("mmOut");

    // content
    contentPanel.clear();
    contentPanel.setStyleName("content");
    contentPanel.add(loginPanel);
    contentPanel.add(loginMessage);
    contentPanel.add(txtInPanel);
    contentPanel.add(asrPanel);
    contentPanel.add(textPanel);
    contentPanel.add(audioPanel);
    contentPanel.add(mmPanel);

    // foot
    String foot = "<div id='foot'></div>";
    footPanel.clear();
    footPanel.add(new HTML(foot));

    // other panels to change the layout can be added if needed
    // headPanel.setStyleName("layout");
    // titlePanel.setStyleName("layout");
    // contentPanel.setStyleName("layout");
    // footPanel.setStyleName("layout");

    if (login != null) {
        if (login.equals("1")) {
            stopReload();
            loggedIn();
        } else {
            loadLoginScreen();
        }
    } else {
        loadLoginScreen();
    }

    // RootPanel.get().clear();
    RootPanel.get("head").add(headPanel);
    RootPanel.get("title").add(titlePanel);
    RootPanel.get("content").add(contentPanel);
    RootPanel.get("foot").add(footPanel);

    // handler
    // login click
    loginClickHandler = new ClickHandler() {
        public void onClick(ClickEvent event) {
            login();
        }
    };

    if (loginClickHandlerRegistration != null) {
        loginClickHandlerRegistration.removeHandler();
    }

    loginClickHandlerRegistration = loginButton.addClickHandler(loginClickHandler);

    // login keypress
    loginUserKeyPressHandler = new KeyPressHandler() {
        public void onKeyPress(KeyPressEvent event) {
            if (event.getCharCode() == KeyCodes.KEY_ENTER) {
                login();
            }
        }

    };
    if (loginUserKeyPressHandlerRegistration != null) {
        loginUserKeyPressHandlerRegistration.removeHandler();
    }
    loginUserKeyPressHandlerRegistration = userTextBox.addKeyPressHandler(loginUserKeyPressHandler);

    loginPWKeyPressHandler = new KeyPressHandler() {
        public void onKeyPress(KeyPressEvent event) {
            if (event.getCharCode() == KeyCodes.KEY_ENTER) {
                login();
            }
        }

    };
    if (loginPWKeyPressHandlerRegistration != null) {
        loginPWKeyPressHandlerRegistration.removeHandler();
    }
    loginPWKeyPressHandlerRegistration = pwTextBox.addKeyPressHandler(loginPWKeyPressHandler);

    // logout click
    logoutClickHandler = new ClickHandler() {
        public void onClick(ClickEvent event) {
            logout();
        }
    };
    if (logoutClickHandlerRegistration != null) {
        logoutClickHandlerRegistration.removeHandler();
    }
    logoutClickHandlerRegistration = logoutButton.addClickHandler(logoutClickHandler);

    // send click
    sendClickHandler = new ClickHandler() {
        public void onClick(ClickEvent event) {
            reload = false;
            getTimeStamp(textInputTextArea.getText());
            textInputTextArea.setText("");
        }
    };
    if (sendClickHandlerRegistration != null) {
        sendClickHandlerRegistration.removeHandler();
    }
    sendClickHandlerRegistration = sendButton.addClickHandler(sendClickHandler);

    // send keypress
    sendKeyPressHandler = new KeyPressHandler() {
        public void onKeyPress(KeyPressEvent event) {
            if (event.getCharCode() == KeyCodes.KEY_ENTER) {
                reload = false;
                getTimeStamp(textInputTextArea.getText());
                textInputTextArea.setText("");
            }
        }
    };
    if (sendKeyPressHandlerRegistration != null) {
        sendKeyPressHandlerRegistration.removeHandler();
    }
    sendKeyPressHandlerRegistration = textInputTextArea.addKeyPressHandler(sendKeyPressHandler);

    refreshTimer = new Timer() {
        @Override
        public void run() {
            if (reload) {
                getData();
            }
        }
    };

    // run refresh
    refreshTimer.scheduleRepeating(REFRESH_INTERVAL);

}

From source file:cz.filmtit.client.widgets.FileVideoWidget.java

License:Open Source License

public FileVideoWidget(String src, SubtitleSynchronizer synchronizer, Boolean autoplay) {
    initWidget(uiBinder.createAndBindUi(this));

    if (src != null && !src.isEmpty()) {

        player = Video.createIfSupported();
        player.setWidth("400px");
        player.setHeight("260px");
        player.addSource(src);//from   w  w  w.java  2 s. c o  m
        player.setControls(true);
        player.load();

        this.autoplay = autoplay;

        this.synchronizer = synchronizer;

        currentTime = 0;
        currentLoaded = new HashSet<TranslationResult>();

        timer = new Timer() {
            @Override
            public void run() {
                if (!player.isPaused() && !player.hasEnded() && (player.getCurrentTime() > 0)) {
                    updateLabels();
                }
            }
        };

        timer.scheduleRepeating(100);

        leftLabel = new Label("");
        leftLabel.setWidth("292px");
        leftLabel.setHeight("100%");
        leftLabel.addStyleName("subtitleDisplayedLeft");

        rightLabel = new Label("");
        rightLabel.setWidth("292px");
        rightLabel.setHeight("100%");
        rightLabel.addStyleName("subtitleDisplayedRight");

        videoWrapper.add(leftLabel);
        videoWrapper.add(player);
        videoWrapper.add(rightLabel);

    }

    buttonPanel = new ButtonPanel(TranslationWorkspace.getCurrentWorkspace());
    panelWrapper.add(buttonPanel);
}

From source file:nl.mpi.tg.eg.experiment.client.view.TimedStimulusView.java

License:Open Source License

public Element addTimedVideo(final TimedEventMonitor timedEventMonitor, final SafeUri oggPath,
        final SafeUri ogvPath, final SafeUri mp4Path, int percentOfPage, int maxHeight, int maxWidth,
        final String styleName, final boolean autoPlay, final boolean loop, final boolean showControls,
        final CancelableStimulusListener loadedStimulusListener,
        final CancelableStimulusListener failedStimulusListener,
        final CancelableStimulusListener playbackStartedStimulusListener,
        final CancelableStimulusListener playedStimulusListener, final String mediaId) {
    cancelableListnerList.add(loadedStimulusListener);
    cancelableListnerList.add(failedStimulusListener);
    cancelableListnerList.add(playbackStartedStimulusListener);
    cancelableListnerList.add(playedStimulusListener);
    final Element videoElement;
    if (timedEventMonitor != null) {
        timedEventMonitor.registerEvent("addTimedVideo");
    }/*from   w  w  w. jav a 2 s  .com*/
    final Video video = Video.createIfSupported();
    if (video == null) {
        failedStimulusListener.postLoadTimerFired();
        videoElement = null;
    } else {
        video.setAutoplay(autoPlay);
        videoList.put(mediaId, video);
        //            video.setPoster(poster);
        video.setControls(showControls);
        video.setPreload(MediaElement.PRELOAD_AUTO);
        if (styleName != null && !styleName.isEmpty()) {
            video.addStyleName(styleName);
        } else {
            addSizeAttributes(video.getElement(), percentOfPage, maxHeight, maxWidth);
        }
        getActivePanel().add(video);
        video.addCanPlayThroughHandler(new CanPlayThroughHandler() {
            boolean hasTriggeredOnLoaded = false;

            @Override
            public void onCanPlayThrough(CanPlayThroughEvent event) {
                if (!hasTriggeredOnLoaded) {
                    if (timedEventMonitor != null) {
                        timedEventMonitor.registerEvent("videoCanPlayThrough");
                    }
                    hasTriggeredOnLoaded = true;
                    loadedStimulusListener.postLoadTimerFired();
                    if (autoPlay) {
                        video.play();
                    }
                    if (video.getError() != null) {
                        // todo: check that this method is functioning correctly and if not then use the method in audioPlayer.@nl.mpi.tg.eg.experiment.client.service.AudioPlayer::onAudioFailed()();
                        failedStimulusListener.postLoadTimerFired();
                    }
                }
            }
        });
        new VideoPlayer().addNativeCallbacks(timedEventMonitor, video.getVideoElement(),
                playbackStartedStimulusListener);
        //            todo: move the video handling code from here into the VideoPlayer class, in such a way is it can be used like the AudioPlayer class of the same package
        video.addEndedHandler(new EndedHandler() {
            private boolean triggered = false;

            @Override
            public void onEnded(EndedEvent event) {
                if (timedEventMonitor != null) {
                    timedEventMonitor.registerEvent("videoEnded");
                    timedEventMonitor.registerMediaLength(mediaId, (long) (video.getCurrentTime() * 1000));
                }
                // prevent multiple triggering
                if (!triggered) {
                    triggered = true;
                    //                        Timer timer = new Timer() {
                    //                            public void run() {
                    playedStimulusListener.postLoadTimerFired();
                    //                            }
                    //                        };
                    //                        timerList.add(timer);
                    //                        timer.schedule(postLoadMs);
                }
            }
        });
        if (oggPath != null) {
            video.addSource(oggPath.asString(), "video/ogg");
        }
        if (ogvPath != null) {
            video.addSource(ogvPath.asString(), "video/ogg");
        }
        if (mp4Path != null) {
            video.addSource(mp4Path.asString(), "video/mp4");
        }

        if (!autoPlay) {
            video.pause();
            video.setCurrentTime(0);
        }
        video.setLoop(loop);
        video.load();
        if (video.getError() != null) {
            // todo: check that this method is functioning correctly and if not then use the method in audioPlayer.@nl.mpi.tg.eg.experiment.client.service.AudioPlayer::onAudioFailed()();
            failedStimulusListener.postLoadTimerFired();
        }
        videoElement = video.getElement();
    }
    return videoElement;
}

From source file:nl.mpi.tg.eg.experiment.client.view.VideoPanel.java

License:Open Source License

public VideoPanel(String width, String poster, String src) {
    video = Video.createIfSupported();
    if (video != null) {
        video.setPoster(poster);/* w  ww.j a  v  a2s. c om*/
        video.setControls(true);
        video.setPreload(MediaElement.PRELOAD_AUTO);
        this.add(video);
    } else {
        this.add(new Label("Video is not supported"));
    }
    addSource(src + ".mp4", "video/mp4");
    addSource(src + ".ogg", "video/ogg");
    addSource(src + ".webm", "video/webm");
}

From source file:org.jbpm.form.builder.ng.model.client.form.items.VideoFormItem.java

License:Apache License

@Override
public Widget cloneDisplay(Map<String, Object> formData) {
    Video v = Video.createIfSupported();
    if (v == null) {
        return new Label(notSupported.getText());
    }/*from   w w  w.  ja  v  a2s  .com*/
    populate(v);
    Object input = getInputValue(formData);
    if (v != null && input != null) {
        String url = input.toString();
        v.setSrc(url);
        if (url.endsWith(".ogv")) {
            v.getElement().setPropertyString("type", "video/ogg");
        } else if (url.endsWith(".mpeg") || url.endsWith(".mpg")) {
            v.getElement().setPropertyString("type", "video/mpeg");
        } else if (url.endsWith(".avi")) {
            v.getElement().setPropertyString("type", "video/avi");
        }
    }
    super.populateActions(v.getElement());
    return v;
}

From source file:org.roda.wui.client.browse.BitstreamPreview.java

private void videoPreview() {
    Video videoPlayer = Video.createIfSupported();
    if (videoPlayer != null) {
        videoPlayer.addSource(bitstreamDownloadUri.asString(), getVideoSourceType());
        videoPlayer.setControls(true);/*  ww w.  j  a va  2s  .c o m*/
        panel.add(videoPlayer);
        videoPlayer.addStyleName("viewRepresentationAudioFilePreview");
    } else {
        notSupportedPreview();
    }
}