Show open requester if no file argument given.
authorNot Zed <notzed@gmail.com>
Tue, 7 Dec 2021 23:13:12 +0000 (09:43 +1030)
committerNot Zed <notzed@gmail.com>
Tue, 7 Dec 2021 23:13:12 +0000 (09:43 +1030)
Use threadFactory to create thread rather than to-be-deprecated new Thread()

src/notzed.jjmpeg.demo/classes/au/notzed/jjmpeg/demo/video/VideoPlay.java

index 112c761..026f536 100644 (file)
@@ -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<String> 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();
        }