diff --git a/ui/src/main/java/dev/quoije/umd/ui/PlayerApp.java b/ui/src/main/java/dev/quoije/umd/ui/PlayerApp.java index 261f71e..8c80233 100644 --- a/ui/src/main/java/dev/quoije/umd/ui/PlayerApp.java +++ b/ui/src/main/java/dev/quoije/umd/ui/PlayerApp.java @@ -21,9 +21,12 @@ import javafx.application.Application; import javafx.application.Platform; import javafx.scene.Scene; import javafx.scene.canvas.Canvas; +import javafx.scene.canvas.GraphicsContext; import javafx.scene.image.PixelFormat; +import javafx.scene.image.WritableImage; import javafx.scene.input.KeyCode; import javafx.scene.layout.StackPane; +import javafx.scene.paint.Color; import javafx.stage.Stage; import java.io.IOException; @@ -39,16 +42,21 @@ public final class PlayerApp extends Application { private Canvas videoCanvas; private RcoRenderer renderer; private volatile Controller controller; + private volatile MoviePlayer moviePlayer; @Override public void start(Stage stage) { - String isoPath = getParameters().getRaw().isEmpty() ? null : getParameters().getRaw().get(0); + // Gradle's --args splits on whitespace; rejoin so paths with spaces work. + String isoPath = getParameters().getRaw().isEmpty() + ? null + : String.join(" ", getParameters().getRaw()); menuCanvas = new Canvas(WIDTH, HEIGHT); videoCanvas = new Canvas(WIDTH, HEIGHT); StackPane root = new StackPane(videoCanvas, menuCanvas); Scene scene = new Scene(root, WIDTH, HEIGHT); + scene.setFill(Color.BLACK); stage.setTitle("useless-umd-player"); stage.setScene(scene); stage.show(); @@ -105,7 +113,7 @@ public final class PlayerApp extends Application { int audioFlag, int subtitleNumber, int subtitleFlag) { Playlist.Stream stream = playlist.streamForPlayListNumber(playListNumber); if (stream != null) { - startPlayback(isoPath, stream.name()); + startPlayback(isoPath, stream.name(), playListNumber); } } @@ -130,13 +138,14 @@ public final class PlayerApp extends Application { interpreter.run(globals); controller = (Controller) controllerObject.getObject(); + moviePlayer = (MoviePlayer) movieplayer.getObject(); controller.callCallback(interpreter, "onAutoPlay", null); } catch (Exception e) { e.printStackTrace(); } } - private void startPlayback(String isoPath, String streamName) { + private void startPlayback(String isoPath, String streamName, int playListNumber) { Thread player = new Thread(() -> { try (UmdIsoReader iso = new UmdIsoReader(Path.of(isoPath)); PlaybackEngine engine = PlaybackEngine.open(iso, streamName, 0)) { @@ -164,6 +173,11 @@ public final class PlayerApp extends Application { Thread.sleep(millis, nanos); } } + + MoviePlayer mp = moviePlayer; + if (mp != null) { + mp.onPlayListEnd(playListNumber); + } } catch (Exception e) { e.printStackTrace(); } @@ -173,10 +187,23 @@ public final class PlayerApp extends Application { } private void blitVideo(int[] argb, int width, int height) { + WritableImage image = new WritableImage(width, height); + image.getPixelWriter().setPixels(0, 0, width, height, PixelFormat.getIntArgbInstance(), argb, 0, width); + Platform.runLater(() -> { - videoCanvas.getGraphicsContext2D() - .getPixelWriter() - .setPixels(0, 0, width, height, PixelFormat.getIntArgbInstance(), argb, 0, width); + GraphicsContext g = videoCanvas.getGraphicsContext2D(); + double canvasWidth = videoCanvas.getWidth(); + double canvasHeight = videoCanvas.getHeight(); + + g.setFill(Color.BLACK); + g.fillRect(0, 0, canvasWidth, canvasHeight); + + double scale = java.lang.Math.min(canvasWidth / image.getWidth(), canvasHeight / image.getHeight()); + double drawWidth = image.getWidth() * scale; + double drawHeight = image.getHeight() * scale; + double x = (canvasWidth - drawWidth) / 2; + double y = (canvasHeight - drawHeight) / 2; + g.drawImage(image, x, y, drawWidth, drawHeight); }); }