|
|
|
|
@@ -6,6 +6,7 @@ import com.github.gtache.autosubtitle.modules.gui.Pause;
|
|
|
|
|
import com.github.gtache.autosubtitle.modules.gui.Play;
|
|
|
|
|
import com.github.gtache.autosubtitle.subtitle.Subtitle;
|
|
|
|
|
import com.github.gtache.autosubtitle.subtitle.fx.SubtitleLabel;
|
|
|
|
|
import javafx.application.Platform;
|
|
|
|
|
import javafx.beans.binding.Bindings;
|
|
|
|
|
import javafx.fxml.FXML;
|
|
|
|
|
import javafx.scene.Cursor;
|
|
|
|
|
@@ -53,6 +54,8 @@ public class FXMediaController implements MediaController {
|
|
|
|
|
private final Image playImage;
|
|
|
|
|
private final Image pauseImage;
|
|
|
|
|
|
|
|
|
|
private boolean wasPlaying;
|
|
|
|
|
|
|
|
|
|
@Inject
|
|
|
|
|
FXMediaController(final FXMediaModel model, @Play final Image playImage, @Pause final Image pauseImage) {
|
|
|
|
|
this.model = requireNonNull(model);
|
|
|
|
|
@@ -62,8 +65,8 @@ public class FXMediaController implements MediaController {
|
|
|
|
|
|
|
|
|
|
@FXML
|
|
|
|
|
private void initialize() {
|
|
|
|
|
volumeValueLabel.textProperty().bind(Bindings.createStringBinding(() -> String.valueOf((int) model.volume()), model.volumeProperty()));
|
|
|
|
|
playLabel.textProperty().bind(Bindings.createStringBinding(() -> model.position() + "/" + model.duration(), model.positionProperty(), model.durationProperty()));
|
|
|
|
|
volumeValueLabel.textProperty().bind(Bindings.createStringBinding(() -> String.valueOf((int) (model.volume() * 100)), model.volumeProperty()));
|
|
|
|
|
playLabel.textProperty().bind(Bindings.createStringBinding(() -> formatTime(model.position(), model.duration()), model.positionProperty(), model.durationProperty()));
|
|
|
|
|
model.positionProperty().bindBidirectional(playSlider.valueProperty());
|
|
|
|
|
|
|
|
|
|
model.volumeProperty().addListener((observable, oldValue, newValue) -> volumeSlider.setValue(newValue.doubleValue() * 100));
|
|
|
|
|
@@ -73,6 +76,9 @@ public class FXMediaController implements MediaController {
|
|
|
|
|
final var player = videoView.getMediaPlayer();
|
|
|
|
|
if (player != null) {
|
|
|
|
|
if (Boolean.TRUE.equals(newValue)) {
|
|
|
|
|
if (model.position() == model.duration()) {
|
|
|
|
|
seek(0L);
|
|
|
|
|
}
|
|
|
|
|
player.play();
|
|
|
|
|
} else {
|
|
|
|
|
player.pause();
|
|
|
|
|
@@ -97,10 +103,26 @@ public class FXMediaController implements MediaController {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
playSlider.valueProperty().addListener((observable1, oldValue1, newValue1) -> seek(newValue1.longValue()));
|
|
|
|
|
playSlider.setOnMousePressed(e -> {
|
|
|
|
|
wasPlaying = model.isPlaying();
|
|
|
|
|
model.setIsPlaying(false);
|
|
|
|
|
});
|
|
|
|
|
playSlider.valueProperty().addListener(observable1 -> {
|
|
|
|
|
if (playSlider.isValueChanging()) {
|
|
|
|
|
seek((long) playSlider.getValue());
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
playSlider.setOnMouseReleased(e -> {
|
|
|
|
|
final var value = playSlider.getValue();
|
|
|
|
|
Platform.runLater(() -> {
|
|
|
|
|
seek((long) value);
|
|
|
|
|
model.setIsPlaying(wasPlaying);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
player.volumeProperty().bindBidirectional(model.volumeProperty());
|
|
|
|
|
player.setOnPlaying(() -> model.setIsPlaying(true));
|
|
|
|
|
player.setOnPaused(() -> model.setIsPlaying(false));
|
|
|
|
|
player.setOnEndOfMedia(() -> model.setIsPlaying(false));
|
|
|
|
|
playSlider.setMax(model.duration());
|
|
|
|
|
playSlider.setValue(0L);
|
|
|
|
|
videoView.setMediaPlayer(player);
|
|
|
|
|
@@ -168,4 +190,26 @@ public class FXMediaController implements MediaController {
|
|
|
|
|
label.setOnMouseEntered(mouseEvent -> label.setCursor(Cursor.HAND));
|
|
|
|
|
return label;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String formatTime(final long position, final long duration) {
|
|
|
|
|
final var positionString = formatTime(position);
|
|
|
|
|
final var durationString = formatTime(duration);
|
|
|
|
|
return positionString + "/" + durationString;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private static String formatTime(final long time) {
|
|
|
|
|
var intDuration = (int) time / 1000;
|
|
|
|
|
final var durationHours = intDuration / (60 * 60);
|
|
|
|
|
if (durationHours > 0) {
|
|
|
|
|
intDuration -= durationHours * 60 * 60;
|
|
|
|
|
}
|
|
|
|
|
final var durationMinutes = intDuration / 60;
|
|
|
|
|
final var durationSeconds = intDuration - durationHours * 60 * 60
|
|
|
|
|
- durationMinutes * 60;
|
|
|
|
|
if (durationHours > 0) {
|
|
|
|
|
return String.format("%d:%02d:%02d", durationHours, durationMinutes, durationSeconds);
|
|
|
|
|
} else {
|
|
|
|
|
return String.format("%02d:%02d", durationMinutes, durationSeconds);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|