From 69aca695eb4acec2b2cd537d8c8336cbbbaf49f0 Mon Sep 17 00:00:00 2001 From: Not Zed Date: Wed, 8 Dec 2021 09:43:12 +1030 Subject: [PATCH] Show open requester if no file argument given. Use threadFactory to create thread rather than to-be-deprecated new Thread() --- .../notzed/jjmpeg/demo/video/VideoPlay.java | 22 ++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/src/notzed.jjmpeg.demo/classes/au/notzed/jjmpeg/demo/video/VideoPlay.java b/src/notzed.jjmpeg.demo/classes/au/notzed/jjmpeg/demo/video/VideoPlay.java index 112c761..026f536 100644 --- a/src/notzed.jjmpeg.demo/classes/au/notzed/jjmpeg/demo/video/VideoPlay.java +++ b/src/notzed.jjmpeg.demo/classes/au/notzed/jjmpeg/demo/video/VideoPlay.java @@ -21,6 +21,7 @@ package au.notzed.jjmpeg.demo.video; import au.notzed.jjmpeg.AVIOException; import au.notzed.jjmpeg.fx.FXPixelReader; import au.notzed.jjmpeg.io.JJMediaReader; +import java.io.File; import java.io.FileNotFoundException; import java.io.IOException; import static java.lang.Double.min; @@ -30,6 +31,7 @@ import java.time.ZoneId; import java.time.format.DateTimeFormatter; import java.util.List; import java.util.concurrent.CountDownLatch; +import java.util.concurrent.Executors; import javafx.application.Application; import javafx.application.Platform; import javafx.beans.InvalidationListener; @@ -51,6 +53,7 @@ import javafx.scene.paint.Color; import javafx.scene.text.Text; import javafx.scene.transform.Scale; import javafx.scene.transform.Translate; +import javafx.stage.FileChooser; import javafx.stage.Screen; import javafx.stage.Stage; @@ -69,13 +72,22 @@ public class VideoPlay extends Application { List args = getParameters().getUnnamed(); if (args.size() != 1) { - Alert a = new Alert(Alert.AlertType.ERROR, "Must supply one file.", ButtonType.CLOSE); - a.showAndWait(); - return; + FileChooser fc = new FileChooser(); + File selected; + + fc.setTitle("Select Video"); + selected = fc.showOpenDialog(null); + + if (selected == null) + return; + + args = List.of(selected.getAbsolutePath()); } - new Thread(() -> { - reader(args.get(0)); + String path = args.get(0); + + Executors.defaultThreadFactory().newThread(() -> { + reader(path); }).start(); } -- 2.39.5