private void playVideo(Media media) { timeProgress.setTextFill(Color.WHITE); npView.setVisible(true); mView.toBack(); btnPaFull.setImage(new Image("icon/Full_button/full.png")); go = true; if (mediaView.isVisible() == false) { mediaView.setVisible(true); display.setVisible(false); } if (mp != null) { mp.dispose(); } mp = new MediaPlayer(media); mediaView.setMediaPlayer(mp); mediaView.setPreserveRatio(true); final DoubleProperty width = mediaView.fitWidthProperty(); final DoubleProperty height = mediaView.fitHeightProperty(); width.bind(Bindings.selectDouble(mediaView.sceneProperty(), "width")); height.bind(Bindings.selectDouble(mediaView.sceneProperty(), "height")); mp.play(); }
public void start() { movie = new MediaPlayer(path); movie.play(); VIEW.setMediaPlayer(movie); movie .currentTimeProperty() .addListener( new ChangeListener<javafx.util.Duration>() { @Override public void changed( ObservableValue<? extends javafx.util.Duration> observable, javafx.util.Duration duration, javafx.util.Duration current) { timeSlider.setValue(current.toSeconds()); } }); movie.setOnReady( new Runnable() { @Override public void run() { timeSlider.setMin(0); timeSlider.setValue(0.0); timeSlider.setMax(movie.getTotalDuration().toSeconds()); volumeSlider.setMin(0); volumeSlider.setValue(0.5); } }); timeSlider.setOnMouseClicked( new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent event) { movie.seek(javafx.util.Duration.seconds(timeSlider.getValue())); } }); volumeSlider .valueProperty() .addListener( new InvalidationListener() { @Override public void invalidated(Observable observable) { if (volumeSlider.isValueChanging()) { movie.setVolume(volumeSlider.getValue() / 100); } } }); }