Fixes performance, volume and seek problems, updates label
This commit is contained in:
@@ -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.modules.gui.Play;
|
||||||
import com.github.gtache.autosubtitle.subtitle.Subtitle;
|
import com.github.gtache.autosubtitle.subtitle.Subtitle;
|
||||||
import com.github.gtache.autosubtitle.subtitle.fx.SubtitleLabel;
|
import com.github.gtache.autosubtitle.subtitle.fx.SubtitleLabel;
|
||||||
|
import javafx.application.Platform;
|
||||||
import javafx.beans.binding.Bindings;
|
import javafx.beans.binding.Bindings;
|
||||||
import javafx.fxml.FXML;
|
import javafx.fxml.FXML;
|
||||||
import javafx.scene.Cursor;
|
import javafx.scene.Cursor;
|
||||||
@@ -53,6 +54,8 @@ public class FXMediaController implements MediaController {
|
|||||||
private final Image playImage;
|
private final Image playImage;
|
||||||
private final Image pauseImage;
|
private final Image pauseImage;
|
||||||
|
|
||||||
|
private boolean wasPlaying;
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
FXMediaController(final FXMediaModel model, @Play final Image playImage, @Pause final Image pauseImage) {
|
FXMediaController(final FXMediaModel model, @Play final Image playImage, @Pause final Image pauseImage) {
|
||||||
this.model = requireNonNull(model);
|
this.model = requireNonNull(model);
|
||||||
@@ -62,8 +65,8 @@ public class FXMediaController implements MediaController {
|
|||||||
|
|
||||||
@FXML
|
@FXML
|
||||||
private void initialize() {
|
private void initialize() {
|
||||||
volumeValueLabel.textProperty().bind(Bindings.createStringBinding(() -> String.valueOf((int) model.volume()), model.volumeProperty()));
|
volumeValueLabel.textProperty().bind(Bindings.createStringBinding(() -> String.valueOf((int) (model.volume() * 100)), model.volumeProperty()));
|
||||||
playLabel.textProperty().bind(Bindings.createStringBinding(() -> model.position() + "/" + model.duration(), model.positionProperty(), model.durationProperty()));
|
playLabel.textProperty().bind(Bindings.createStringBinding(() -> formatTime(model.position(), model.duration()), model.positionProperty(), model.durationProperty()));
|
||||||
model.positionProperty().bindBidirectional(playSlider.valueProperty());
|
model.positionProperty().bindBidirectional(playSlider.valueProperty());
|
||||||
|
|
||||||
model.volumeProperty().addListener((observable, oldValue, newValue) -> volumeSlider.setValue(newValue.doubleValue() * 100));
|
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();
|
final var player = videoView.getMediaPlayer();
|
||||||
if (player != null) {
|
if (player != null) {
|
||||||
if (Boolean.TRUE.equals(newValue)) {
|
if (Boolean.TRUE.equals(newValue)) {
|
||||||
|
if (model.position() == model.duration()) {
|
||||||
|
seek(0L);
|
||||||
|
}
|
||||||
player.play();
|
player.play();
|
||||||
} else {
|
} else {
|
||||||
player.pause();
|
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.volumeProperty().bindBidirectional(model.volumeProperty());
|
||||||
player.setOnPlaying(() -> model.setIsPlaying(true));
|
player.setOnPlaying(() -> model.setIsPlaying(true));
|
||||||
player.setOnPaused(() -> model.setIsPlaying(false));
|
player.setOnPaused(() -> model.setIsPlaying(false));
|
||||||
|
player.setOnEndOfMedia(() -> model.setIsPlaying(false));
|
||||||
playSlider.setMax(model.duration());
|
playSlider.setMax(model.duration());
|
||||||
playSlider.setValue(0L);
|
playSlider.setValue(0L);
|
||||||
videoView.setMediaPlayer(player);
|
videoView.setMediaPlayer(player);
|
||||||
@@ -168,4 +190,26 @@ public class FXMediaController implements MediaController {
|
|||||||
label.setOnMouseEntered(mouseEvent -> label.setCursor(Cursor.HAND));
|
label.setOnMouseEntered(mouseEvent -> label.setCursor(Cursor.HAND));
|
||||||
return label;
|
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);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ public class FXMediaModel implements MediaModel {
|
|||||||
@Inject
|
@Inject
|
||||||
FXMediaModel() {
|
FXMediaModel() {
|
||||||
this.video = new SimpleObjectProperty<>();
|
this.video = new SimpleObjectProperty<>();
|
||||||
this.volume = new SimpleDoubleProperty(0.0);
|
this.volume = new SimpleDoubleProperty(1.0d);
|
||||||
this.isPlaying = new SimpleBooleanProperty(false);
|
this.isPlaying = new SimpleBooleanProperty(false);
|
||||||
this.duration = new ReadOnlyLongWrapper(0);
|
this.duration = new ReadOnlyLongWrapper(0);
|
||||||
this.position = new SimpleLongProperty(0);
|
this.position = new SimpleLongProperty(0);
|
||||||
|
|||||||
@@ -51,7 +51,7 @@ public class FXWorkModel implements WorkModel {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<EditableSubtitle> originalSubtitles() {
|
public List<EditableSubtitle> originalSubtitles() {
|
||||||
return List.of();
|
return originalSubtitles;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -40,7 +40,7 @@
|
|||||||
</HBox.margin>
|
</HBox.margin>
|
||||||
</Button>
|
</Button>
|
||||||
<Label text="%media.volume.label"/>
|
<Label text="%media.volume.label"/>
|
||||||
<Slider fx:id="volumeSlider"/>
|
<Slider fx:id="volumeSlider" value="100"/>
|
||||||
<Label fx:id="volumeValueLabel" text="Label"/>
|
<Label fx:id="volumeValueLabel" text="Label"/>
|
||||||
</children>
|
</children>
|
||||||
<padding>
|
<padding>
|
||||||
|
|||||||
Reference in New Issue
Block a user