List of usage examples for com.google.gwt.dom.client Document createKeyPressEvent
public NativeEvent createKeyPressEvent(boolean ctrlKey, boolean altKey, boolean shiftKey, boolean metaKey, int charCode)
From source file:com.bramosystems.oss.player.core.client.ui.FlashMediaPlayer.java
License:Apache License
/** * Constructs <code>FlashMediaPlayer</code> with the specified {@code height} and * {@code width} to playback media located at {@code mediaURL}. Media playback * begins automatically if {@code autoplay} is {@code true}. * * <p> {@code height} and {@code width} are specified as CSS units. A value of {@code null} * for {@code height} or {@code width} puts the player in embedded mode. When in embedded mode, * the player is made invisible on the page and media state events are propagated to registered * listeners only. This is desired especially when used with custom sound controls. For custom * video-playback control, specify valid CSS values for {@code height} and {@code width} but hide the * player controls with {@code setControllerVisible(false)}. * * @param mediaURL the URL of the media to playback * @param autoplay {@code true} to start playing automatically, {@code false} otherwise * @param height the height of the player * @param width the width of the player. * * @throws PluginVersionException if the required Flash plugin version is not installed on the client. * @throws PluginNotFoundException if the Flash plugin is not installed on the client. *///w w w . j a v a2 s.c om public FlashMediaPlayer(final String mediaURL, final boolean autoplay, String height, String width) throws PluginNotFoundException, PluginVersionException { this(); _height = height; _width = width; isEmbedded = (height == null) || (width == null); if (isEmbedded) { _height = "0px"; _width = "0px"; } swf = new SWFWidget(FMPStateManager.getSWFImpl(), "100%", _height, req); swf.setFlashVar("playerId", swf.getId()); swf.setFlashVar("autoplay", Boolean.toString(autoplay)); swf.setFlashVar("evtPfx", ((CorePlayerProvider) getWidgetFactory("core")).getFMPHandlerPrefix(swf.getId())); swf.setFlashVar("mediaURL", URL.encodePathSegment(mediaURL)); swf.commitFlashVars(); swf.addProperty("allowScriptAccess", "always"); swf.addProperty("allowFullScreen", "true"); swf.addProperty("bgcolor", "#000000"); playerId = swf.getId(); ((CorePlayerProvider) getWidgetFactory("core")).initFMPHandler(playerId, new FMPStateManager.FMPStateCallback() { @Override public void onInit() { impl = FlashMediaPlayerImpl.getPlayer(playerId); for (String url : _playlistCache) { impl.addToPlaylist(url); } firePlayerStateEvent(PlayerStateEvent.State.Ready); } @Override public void onMessage(int type, String message) { if (type == 1) { fireError(message); } else { fireDebug(message); } } @Override public void onProgress(double progress) { fireLoadingProgress(progress); } @Override public void onMediaInfo(String info) { MediaInfo mi = new MediaInfo(); FMPStateManager.fillMediaInfoImpl(info, mi); fireMediaInfoAvailable(mi); } @Override public void onEvent(int type, boolean buttonDown, boolean alt, boolean ctrl, boolean shift, boolean cmd, int stageX, int stageY) { int button = buttonDown ? NativeEvent.BUTTON_LEFT : NativeEvent.BUTTON_RIGHT; int screenX = -1, screenY = -1; Document _doc = Document.get(); NativeEvent event = null; switch (type) { case 1: // mouse down event = _doc.createMouseDownEvent(1, screenX, screenY, stageX, stageY, ctrl, alt, shift, cmd, button); break; case 2: // mouse up event = _doc.createMouseUpEvent(1, screenX, screenY, stageX, stageY, ctrl, alt, shift, cmd, button); break; case 3: // mouse move event = _doc.createMouseMoveEvent(1, screenX, screenY, stageX, stageY, ctrl, alt, shift, cmd, button); break; case 10: // click event = _doc.createClickEvent(1, screenX, screenY, stageX, stageY, ctrl, alt, shift, cmd); break; case 11: // double click event = _doc.createDblClickEvent(1, screenX, screenY, stageX, stageY, ctrl, alt, shift, cmd); break; case 20: // key down event = _doc.createKeyDownEvent(ctrl, alt, shift, cmd, stageX); break; case 21: // key press event = _doc.createKeyPressEvent(ctrl, alt, shift, cmd, stageX); break; case 22: // key up event = _doc.createKeyUpEvent(ctrl, alt, shift, cmd, stageX); break; } DomEvent.fireNativeEvent(event, FlashMediaPlayer.this); } @Override public void onStateChanged(int stateId, int listIndex) { switch (stateId) { case 1: // loading started... //// listener.onPlayerReady(); break; case 2: // play started... firePlayStateEvent(PlayStateEvent.State.Started, listIndex); break; case 3: // play stopped... firePlayStateEvent(PlayStateEvent.State.Stopped, listIndex); break; case 4: // play paused... firePlayStateEvent(PlayStateEvent.State.Paused, listIndex); break; case 9: // play finished... firePlayStateEvent(PlayStateEvent.State.Finished, listIndex); break; case 10: // loading complete ... fireLoadingProgress(1.0); break; } } @Override public void onFullScreen(boolean fullscreen) { firePlayerStateEvent(fullscreen ? PlayerStateEvent.State.FullScreenStarted : PlayerStateEvent.State.FullScreenFinished); } }); if (!isEmbedded) { addMediaInfoHandler(new MediaInfoHandler() { @Override public void onMediaInfoAvailable(MediaInfoEvent event) { MediaInfo info = event.getMediaInfo(); if (info.getAvailableItems().contains(MediaInfoKey.VideoHeight) || info.getAvailableItems().contains(MediaInfoKey.VideoWidth)) { checkVideoSize(Integer.parseInt(info.getItem(MediaInfoKey.VideoHeight)), Integer.parseInt(info.getItem(MediaInfoKey.VideoWidth))); } } }); } initWidget(swf); }