Java Reference
In-Depth Information
slider.valueProperty().addListener((ObservableValue<?
extends Number> observable,
Number oldValue, Number newValue) -> {
if (slider.isPressed()) {
long dur = newValue.intValue() * 1000;
mediaPlayer.seek(new Duration(dur));
}
});
Moving right along, you next implement a drag-dropped EventHandler to
handle the media file being dropped into the application window area. Here the ex-
ample first checks to see whether there was a previous mediaPlayer . If there was,
the previous mediaPlayer object is stopped and cleanup is performed:
// stop previous media player and clean up
if (mediaPlayer != null) {
mediaPlayer.stop();
mediaPlayer.currentTimeProperty().removeListener(progressListener);
mediaPlayer.setOnPaused(null);
mediaPlayer.setOnPlaying(null);
mediaPlayer.setOnReady(null);
}
...
// play video when ready status
mediaPlayer.setOnReady(() -> {
progressSlider.setValue(1);
progressSlider.setMax(mediaPlayer.getMedia().getDuration().toMillis()
/ 1000);
mediaPlayer.play();
});// setOnReady()
As with the audio player, you create a Runnable instance to be run when the me-
dia player is in a ready state. You'll notice also that the progressSlider control
uses values in seconds.
Search WWH ::




Custom Search