private void addBackgroundMediaView() { Media media = new Media(MovieView.class.getResource("/backdrop-video.mp4").toExternalForm()); MediaPlayer player = new MediaPlayer(media); player.setMute(true); MediaView mediaView = new MediaView(player); mediaView.setOpacity(.3); getChildren().add(mediaView); mediaView.visibleProperty().bind(getSkinnable().showMediaViewBackgroundProperty()); getSkinnable().showMediaViewBackgroundProperty().addListener(it -> { if (getSkinnable().isShowMediaViewBackground()) { /* * Implementing our own infinite loop support. * The built-in cycle count support seems to be buggy. */ player.setOnEndOfMedia(() -> { player.seek(Duration.ZERO); player.play(); }); player.play(); } else { player.stop(); } }); }
public void closeMedia() { final MediaView mediaView = getMediaView(); if (null == mediaView) return; // mediaView.fitHeightProperty().unbind(); mediaView.fitWidthProperty().unbind(); // final MediaPlayer mediaPlayer = mediaView.getMediaPlayer(); if (null != mediaPlayer) { mediaPlayer.stop(); mediaPlayer.volumeProperty().unbind(); mediaPlayer.onReadyProperty().unbind(); mediaPlayer.dispose(); // mediaView.setOnScroll(null); mediaView.setOnMouseClicked(null); mediaView.setMediaPlayer(null); } // getChildren().remove(mediaView); MEDIA_VIEW.set(null); }
public VideoPlayer(String p) { super(); this.file = new Media(p); this.player = new MediaPlayer(this.file); this.view = new MediaView(this.player); this.pane = new BorderPane(); this.fxScene = new Scene(this.pane); this.pane.setCenter(this.view); this.fxScene.setFill(Paint.valueOf("black")); this.addComponentListener(this); this.addKeyListener(this); this.componentResized(null); this.setScene(this.fxScene); }
@Override public void start(Stage palco) throws Exception { Media media = new Media(VIDEO_URL); // 1 MediaPlayer mediaPlayer = new MediaPlayer(media); // 2 MediaView mediaView = new MediaView(mediaPlayer); // 3 StackPane raiz = new StackPane(); raiz.getChildren().add(mediaView); // 4 Scene cena = new Scene(raiz, 600, 400); palco.setTitle("Tocando Video em JavaFX"); palco.setScene(cena); palco.show(); mediaPlayer.play(); // 4 }
@Override public void start(Stage primaryStage) throws Exception { primaryStage.setTitle("JavaFX Video"); final List<String> args = getParameters().getRaw(); String url = args.size() > 0 ? args.get(args.size() - 1) : "http://www.mediacollege.com/" + "video-gallery/testclips/20051210-w50s.flv"; Media media = new Media(url); MediaPlayer player = new MediaPlayer(media); player.play(); MediaView view = new MediaView(player); Group root = new Group(); root.getChildren().add(view); Scene scene = SceneBuilder.create(). width(360).height(288). root(root). fill(Color.WHITE). build(); primaryStage.setScene(scene); primaryStage.show(); }
private Pane makeViewport() { Pane owner = new Pane(); owner.setPrefSize(1600d, 900d); player.scriptProperty().addListener((p,o,n)->scriptChanged()); media = new MediaView(); owner.getChildren().add(media); // non-media background ScaleListener listener = new ScaleListener(owner, player.context().canvas, media); owner.widthProperty().addListener(listener); owner.heightProperty().addListener(listener); listener.changed(null, 300, 300); owner.setOnMouseClicked((event) -> mouseClicked(event)); owner.getChildren().add(player.context().canvas); return owner; }
protected void initMediaView(){ mediaView = new MediaView(mediaPlayer); mediaView.setOnError(new EventHandler<MediaErrorEvent>() { @Override public void handle(MediaErrorEvent mediaErrorEvent) { // fillQueue(5); //reload media //restartPlayer(Duration.ZERO); logger.debug("MediaView threw an error"); } }); Pane mvPane = new Pane(); mvPane.getChildren().clear(); mvPane.getChildren().add(mediaView); mvPane.setStyle("-fx-background-color: black;"); mvPane.setMinSize(media.getWidth(),media.getHeight()); mvPane.autosize(); setCenter(mvPane); }
private void createScene(final String mediaUrl) { StackPane root = new StackPane(); final Scene scene = new Scene(root); final File f = new File(mediaUrl); final Media m = new Media(f.toURI().toString()); mediaPlayer = new MediaPlayer(m); final MediaView mv = new MediaView(mediaPlayer); final DoubleProperty width = mv.fitWidthProperty(); final DoubleProperty height = mv.fitHeightProperty(); width.bind(Bindings.selectDouble(mv.sceneProperty(), "width")); height.bind(Bindings.selectDouble(mv.sceneProperty(), "height")); mv.setPreserveRatio(true); // mediaPlayer.setAutoPlay(true); // mediaPlayer.setCycleCount(Integer.MAX_VALUE); mediaPlayer.setOnEndOfMedia(new Runnable() { @Override public void run() { replay(); } }); root.getChildren().add(mv); fxContainer.setScene(scene); }
@Override public void initComponents() { media = new Media(getClass().getResource(RESOURCES + "videos/" + mediaName).toString()); mediaPlayer = new MediaPlayer(media); mediaView = new MediaView(mediaPlayer); slideIn = new Timeline(); slideOut = new Timeline(); rightTimer = new Label(); rightTimer.setId("lbl-timer"); leftTimer = new Label(); leftTimer.setId("lbl-timer"); vbox = new VBox(5); vbox.setId("fundo-padrao"); test = new StackPane(); timeSlider = new Slider(); btnPlay = new Button(); btnPlay.setGraphic(new ImageView(imgPause)); btnPlay.setId("btn-play"); final HBox hbox = new HBox(); hbox.setAlignment(Pos.CENTER); hbox.getChildren().addAll(leftTimer, btnPlay, rightTimer); vbox.getChildren().addAll(timeSlider, hbox); getChildren().addAll(mediaView, vbox); mediaPlayer.play(); }
public VideoComponent(JFrame frm, final javafx.embed.swing.JFXPanel vid, javafx.scene.media.MediaPlayer player) { super(null); SwingUtilities.invokeLater(new Runnable() { @Override public void run() { cnt.setLayout(new BorderLayout()); cnt.add(BorderLayout.CENTER, vid); cnt.setVisible(false); } }); Group root = new Group(); v = new MediaView(player); root.getChildren().add(v); vid.setScene(new Scene(root)); this.vid = vid; this.frm = frm; }
@Override public void start(Stage primaryStage) { primaryStage.setTitle("java-buddy.blogspot.com/"); Group root = new Group(); Scene scene = new Scene(root, 540, 210); // create media player Media media = new Media((arg1 != null) ? arg1 : MEDIA_URL); MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.setAutoPlay(true); // create mediaView and add media player to the viewer MediaView mediaView = new MediaView(mediaPlayer); ((Group)scene.getRoot()).getChildren().add(mediaView); primaryStage.setScene(scene); primaryStage.show(); }
public void start(Stage primaryStage) { primaryStage.setTitle("Embedded Media Player"); Group root = new Group(); Scene scene = new Scene(root, 540, 241); // create media player Media media = new Media("D:\\Pradeep\\Funny Mails\\Magic Sand.wmv"); MediaPlayer mediaPlayer = new MediaPlayer(media); mediaPlayer.setAutoPlay(true); StackPane stack = new StackPane(); Text t = new Text("Subtitle.."); // t.textProperty().addChangeListener(..); // MediaControl mediaControl = new MediaControl(mediaPlayer); MediaView m =new MediaView(mediaPlayer); stack.getChildren().addAll(m, t); scene.setRoot(stack); primaryStage.setScene(scene); primaryStage.show(); }
public JFXMovieJFrame() throws HeadlessException { setLayout(new BorderLayout()); add(panel); setSize(480, 320); setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { if (controller != null) { MediaView mediaView = controller.getMediaView(); mediaView.setFitHeight(getHeight()); mediaView.setFitWidth(getWidth()); } } }); }
private JFXMovieJFrameController initJFXNodes(final String location, Consumer<JFXMovieJFrameController> onReadyRunnable) throws IOException { URL controllerLocation = getClass().getResource("/fxml/JFXMovieJFrame.fxml"); FXMLLoader loader = new FXMLLoader(); loader.setLocation(controllerLocation); loader.setBuilderFactory(new JavaFXBuilderFactory()); Parent root = loader.load(controllerLocation.openStream()); controller = loader.getController(); controller.setMediaLocation(location, onReadyRunnable); Scene scene = new Scene(root); scene.getStylesheets().add("/styles/JFXMovieFrame.css"); panel.setScene(scene); MediaView mediaView = controller.getMediaView(); mediaView.setFitWidth(getWidth()); mediaView.setFitHeight(getHeight()); return controller; }
private MediaView createMedieView(MediaPlayer player, MediaInfo info) { MediaView mediaView = new MediaView(player); mediaView.setSmooth(true); mediaView.setPreserveRatio(true); mediaView.fitWidthProperty().bind(mediaViewFitWidth); mediaView.fitHeightProperty().bind(mediaViewFitHeight); mediaView.addEventHandler(MouseEvent.MOUSE_CLICKED, new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { if (event.getClickCount() == 1) { controlPlayPause(); } } }); installMediaInfoTooltip(mediaView, info, 0.8); return mediaView; }
private void controlSaveSnapshot() { MediaView mediaView = videoPane.getMediaView(); if (mediaView == null) { return; } MediaInfo mediaInfo = currentInfoProperty.getValue(); if (mediaInfo == null) { return; } final String title = mediaInfo.titleDescProperty().getValue(); mediaView.snapshot(new Callback<SnapshotResult, Void>() { @Override public Void call(SnapshotResult result) { Image image = result.getImage(); if (image == null) { return null; } if (!saveSnapshotService.isRunning()) { snapshotImageInfoProperty.setValue(new ImageInfo(image, title)); saveSnapshotService.restart(); } return null; } }, null, null); }
public void setMediaView(MediaView view) { List<MediaView> dels = new ArrayList<>(); List<Node> children = getChildren(); for (Node node : children) { if (node instanceof MediaView) { dels.add((MediaView) node); } } if (!dels.isEmpty()) { children.removeAll(dels); } if (view == null) { children.add(0, dummy); } else { children.add(0, view); } }
private static Group createViewer(final MediaPlayer player, final double scale, boolean blur) { Group mediaGroup = new Group(); final MediaView mediaView = new MediaView(player); if (blur) { BoxBlur bb = new BoxBlur(); bb.setWidth(4); bb.setHeight(4); bb.setIterations(1); mediaView.setEffect(bb); } double width = player.getMedia().getWidth(); double height = player.getMedia().getHeight(); mediaView.setFitWidth(width); mediaView.setTranslateX(-width/2.0); mediaView.setScaleX(-scale); mediaView.setFitHeight(height); mediaView.setTranslateY(-height/2.0); mediaView.setScaleY(scale); mediaView.setDepthTest(DepthTest.ENABLE); mediaGroup.getChildren().add(mediaView); return mediaGroup; }
@Override public void start(final Stage primaryStage) throws Exception { MediaView mediaView = new MediaView(); Media media = new Media(new File("credits/end_scene.mp4").toURI().toString()); MediaPlayer mediaPlayer = new MediaPlayer(media); mediaView.setMediaPlayer(mediaPlayer); mediaPlayer.setAutoPlay(true); mediaView.setPreserveRatio(false); List<String> params = getParameters().getRaw(); if(params.size() == 2) { mediaView.setFitWidth(Integer.parseInt(params.get(0))); mediaView.setFitHeight(Integer.parseInt(params.get(1))); } else { mediaView.setFitWidth(1280); mediaView.setFitHeight(720); } mediaPlayer.setOnEndOfMedia(new Runnable() { @Override public void run() { primaryStage.close(); } }); primaryStage.setScene(new Scene(new FlowPane(mediaView))); primaryStage.show(); }
@Override public void newVideo(final Video video) { play.setGraphic(pauseImage); songLength.setText(video.durationProperty().get()); songTitle.setText(video.getTitle()); MediaView videoView = Player.instance().getView(); setVideoView(videoView); }
private void setVideoView(final MediaView videoView) { // FIXME: For Some reason, this is getting called twice menu.getSelectionModel().selectedItemProperty().removeListener(rootController.getMenuListener()); menu.getSelectionModel().select(CategoryType.Videos); menu.getSelectionModel().selectedItemProperty().addListener(rootController.getMenuListener()); Button xButton = new Button("X"); xButton.setOnAction(e -> { rootModel.setSelectedCategory(CategoryType.Videos); }); artwork.setImage(null); VBox container = new VBox(); container.getChildren().add(xButton); container.setBackground(new Background(new BackgroundFill(Paint.valueOf("black"), null, null))); container.setAlignment(Pos.CENTER); double videoWidth = getWidth() - menu.getWidth(); double videoHeight = getHeight() - controlPane.getHeight() - xButton.getHeight() - menuVBox.getHeight(); videoView.setFitWidth(videoWidth); videoView.setFitHeight(videoHeight); videoView.setPreserveRatio(true); VBox.setVgrow(videoView, Priority.ALWAYS); container.getChildren().add(videoView); setCenter(container); widthProperty().addListener((o, old, w) -> videoView.setFitWidth(w.doubleValue() - menu.getWidth())); heightProperty().addListener((o, old, h) -> videoView.setFitHeight(h.doubleValue() - controlPane.getHeight() - menuVBox.getHeight() - xButton.getHeight())); }
@Override public Void call(Object p) { if(isIgnored(p)){return null;} MediaView c = (MediaView) p; DnDPrepare.mediaview(c); return null; }
private void bindContentProgress(MediaView aMediaView, ProgressBar aContentProgress) { if (null == aMediaView || null == aContentProgress) return; final MediaPlayer mediaPlayer = aMediaView.getMediaPlayer(); if (null == mediaPlayer) return; unbindContentProgress(aMediaView, aContentProgress); mContentProgressListener = createContentProgressListener(mediaPlayer, aContentProgress); mediaPlayer.currentTimeProperty().addListener(mContentProgressListener); bindContentProgressClick(mediaPlayer, aContentProgress); }
private void unbindContentProgress(MediaView aMediaView, ProgressBar aContentProgress) { unbindContentProgressClick(aContentProgress); aContentProgress.setProgress(0); if (null == aMediaView || null == mContentProgressListener) return; final MediaPlayer mediaPlayer = aMediaView.getMediaPlayer(); if (null == mediaPlayer) return; mediaPlayer.currentTimeProperty().removeListener(mContentProgressListener); mContentProgressListener = null; }
private void readFileAndSetInitialStateForVideoItem(final File singleFileFromOpenedDialog, final Pane pane) throws IOException { final String openDialogFilePath = singleFileFromOpenedDialog.getPath(); LOGGER.info("now opening: " + openDialogFilePath); final String path = singleFileFromOpenedDialog.toURI().toASCIIString(); final Media mediaVideo = new Media(path); LOGGER.info("mediaVideo opened " + mediaVideo.getSource()); mediaPlayer = new MediaPlayer(mediaVideo); final MediaView mediaView = new MediaView(mediaPlayer); mediaView.setPreserveRatio(true); mediaView.setFitHeight(pane.getHeight()); mediaView.setFitWidth(pane.getWidth()); pane.getChildren().add(mediaView); }
private void readFileAndSetInitialStateForAudioItem(final File singleFileFromOpenedDialog, final VBox vboxPlaylist) throws IOException { final AudioItem audioItem = new AudioItem(); final String openDialogFilePath = singleFileFromOpenedDialog.getPath(); LOGGER.info("Now is opening: " + openDialogFilePath); final String baseName = FilenameUtils.getName(openDialogFilePath); final String path = singleFileFromOpenedDialog.toURI().toASCIIString(); final Media mediaSound = new Media(path); LOGGER.info("MediaSound " + mediaSound.getSource() + " opened"); final MediaPlayer mediaPlayer = new MediaPlayer(mediaSound); final MediaView mediaView = new MediaView(mediaPlayer); setupTimeSliderDependsOnMediaPlayer(audioItem.getSlider(), audioItem.getLabel_for_time(), mediaPlayer); audioItem.getLabel_for_name().setText(baseName); audioItem.getChildren().addAll(mediaView); audioItem.getStop().setOnAction(action -> { mediaPlayer.stop(); alreadyPlaying = false; }); audioItem.getPlay().setOnAction(action -> { if (!alreadyPlaying) { final String formatted = formatDurationForMedia(mediaSound.getDuration()); audioItem.getLabel_for_time().setText(formatted); mediaPlayer.play(); alreadyPlaying = true; } }); vboxPlaylist.getChildren().add(audioItem); }
/** * Доступ к медиаплееру для детельной настройки параметров. * * @return медиаплеер */ public MediaView getMediaView() { int k = 0; while ((medView == null || medView.getMediaPlayer() == null) && k < 30) { k++; try { Thread.sleep(100); } catch (InterruptedException ex) { } } if (medView == null) { throw new ClientException("MediaPlayer = NULL"); } return medView; }
/** * Inherited method to initialize previewing of the file */ @Override void preview() { Media audio = new Media(Paths.get(this.file.getPath()).toUri().toString()); MediaPlayer player = new MediaPlayer(audio); MediaView mediaView = new MediaView(player); HBox mediaControls = new HBox(); mediaControls.getChildren().addAll(new ButtonMaker().makeButton(PLAY, e -> player.play()), new ButtonMaker().makeButton(PAUSE, e -> player.pause()), new ButtonMaker().makeButton(STOP, e -> { player.stop(); this.stage.close(); })); this.group.getChildren().addAll(mediaView, mediaControls); }
@Override public void start(Stage primaryStage) { //Create the video manager manager = new VideoManager("lista.txt"); try { manager.initManager(); } catch (FileNotFoundException | UnsupportedEncodingException e) { e.printStackTrace(); } //Create the view and media with the queue in order to loop recursively MediaView mv = createMediaView(); //Setup fullscreen mode final DoubleProperty width = mv.fitWidthProperty(); final DoubleProperty height = mv.fitHeightProperty(); width.bind(Bindings.selectDouble(mv.sceneProperty(), "width")); height.bind(Bindings.selectDouble(mv.sceneProperty(), "height")); mv.setPreserveRatio(true); StackPane root = new StackPane(); root.getChildren().add(mv); final Scene scene = new Scene(root, 1080, 1920); //Set up the window scene.setFill(Color.BLACK); primaryStage.setScene(scene); primaryStage.setTitle("Full Screen Video Player"); primaryStage.setFullScreen(true); primaryStage.show(); //mv.getMediaPlayer().play(); }
private void initMediaPlayer(final MediaView mediaView) { counter++; if (!manager.isEmpty()) { //Print the queue for test System.out.println(manager.getQueue()); //Get the next item from the manager and move the current item to the end String filename = manager.getNext(); final File f = new File("videos/" + filename + ".mp4"); //Setting up the media to autoplay MediaPlayer mediaPlayer = new MediaPlayer(new Media(f.toURI().toString())); mediaPlayer.setAutoPlay(true); //When the media ends, make a recursive call with the updated queue mediaPlayer.setOnEndOfMedia(()->{ mediaPlayer.dispose(); initMediaPlayer(mediaView); }); System.out.println("Reproduction #"+counter); mediaView.setMediaPlayer(mediaPlayer); }else{ System.out.println("Empty queue"); //There is no videos in the manager, try again in 10 seconds. try { Thread.sleep(15000); } catch (InterruptedException e) { e.printStackTrace(); } initMediaPlayer(mediaView); } }
public void setup(Scene scene) { this.scene = scene; media = new Media(getClass().getResource("video_1.mp4").toExternalForm()); player = new MediaPlayer(media); mediaView = new MediaView(player); player.setAutoPlay(true); player.setVolume(0); getChildren().add(mediaView); mediaView.fitWidthProperty().bind(scene.widthProperty()); mediaView.fitHeightProperty().bind(scene.heightProperty()); }
@Override public Node adjust(Node node, double scale) { requireNonNull(node); requireValidScale(scale); if (node instanceof MediaView) { MediaView mediaView = (MediaView) node; mediaView.fitWidthProperty().set(mediaView.fitWidthProperty().multiply(scale).get()); mediaView.fitHeightProperty().set(mediaView.fitHeightProperty().multiply(scale).get()); } return super.adjust(node, scale); }
@Test public void testGetMediaViewAdjuster() { Adjuster adjuster = Adjuster.getAdjuster(MediaView.class); assertThat(adjuster, is(instanceOf(MediaViewAdjuster.class))); assertThat(adjuster.getNodeClass(), is(sameInstance(MediaView.class))); }
public MediaView getMediaView() { MediaView ret = getMediaView(false); if (ret == dummy) { ret = null; } return ret; }
public MediaView getView() { return new MediaView(currentPlayer); }
private void updateBounds(ObservableValue<? extends Bounds> aObservable, Bounds aOldValue, Bounds aNewValue) { final MediaView mediaView = getMediaView(); if (null == mediaView) return; final MediaPlayer mediaPlayer = mediaView.getMediaPlayer(); if (null == mediaPlayer) return; final Media media = mediaPlayer.getMedia(); if (null == media) return; // final double mediaWidth = media.getWidth(); final double mediaHeight = media.getHeight(); final double mediaRatio = computeRatio(mediaWidth, mediaHeight); // double windowWidth = aNewValue.getWidth(); double windowHeight = aNewValue.getHeight(); // if (windowWidth > 0 && windowHeight > 0) { // double windowRatio = windowWidth / windowHeight; // double viewWidth; double viewHeight; // double viewX; double viewY; // if (windowRatio > mediaRatio) { viewWidth = mediaWidth; viewHeight = mediaWidth / windowRatio; // double extraHeight = mediaHeight - viewHeight; // viewX = 0; viewY = extraHeight / 2; } else { viewWidth = mediaHeight * windowRatio; viewHeight = mediaHeight; // double extraWidth = mediaWidth - viewWidth; // viewX = extraWidth / 2; viewY = 0; } // Rectangle2D viewport = new Rectangle2D(viewX, viewY, viewWidth, viewHeight); mediaView.setViewport(viewport); } }
public void openMedia(String aMediaUri) { if (null == aMediaUri) return; closeMedia(); // Media media = new Media(aMediaUri); MediaPlayer mediaPlayer = new MediaPlayer(media); MediaView mediaView = new MediaView(); mediaView.setMediaPlayer(mediaPlayer); // mediaView.setPreserveRatio(true); mediaView.setSmooth(true); // mediaView.fitHeightProperty().bind(heightProperty()); mediaView.fitWidthProperty().bind(widthProperty()); // mediaPlayer.volumeProperty().bind(VOLUME); mediaPlayer.setOnReady(() -> { final Media mediaReady = mediaPlayer.getMedia(); if (null != mediaReady) { updateBoundsForce(); System.out.println( String.format("Open media: %s (%dx%d)", aMediaUri, mediaReady.getWidth(), mediaReady.getHeight() )); } }); mediaView.setOnMouseClicked((event) -> { final MouseButton mouseButton = event.getButton(); if (MouseButton.SECONDARY == mouseButton) { if (Status.PLAYING == mediaPlayer.getStatus()) { mediaPlayer.pause(); } else { mediaPlayer.play(); } } else if (MouseButton.PRIMARY == mouseButton) { Duration duration = media.getDuration(); Duration newPosition = duration.divide(getWidth()).multiply(event.getX()); mediaPlayer.seek(newPosition); if (Status.PLAYING != mediaPlayer.getStatus()) { mediaPlayer.play(); } } }); mediaView.setOnScroll((event) -> setVolume(getVolume() + event.getDeltaY() * getVolumeZoom())); // MEDIA_VIEW.set(mediaView); getChildren().add(mediaView); updateBoundsForce(); }
public MediaView createMediaView(){ MediaView mediaView = new MediaView(); initMediaPlayer(mediaView); return mediaView; }