简体   繁体   中英

JavaFX MediaPlayer always throws InvocationTargetException on Linux (OpenJFX 11, 15)

I have a problem with the JavaFX Media module on Linux (Ubuntu Budgie). Every time I try to create javafx.scene.media.MediaPlayer , I have this happening:

Exception in Application start method
java.lang.reflect.InvocationTargetException
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplicationWithArgs(LauncherImpl.java:464)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication(LauncherImpl.java:363)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.base/java.lang.reflect.Method.invoke(Method.java:566)
    at java.base/sun.launcher.LauncherHelper$FXHelper.main(LauncherHelper.java:1051)
Caused by: java.lang.RuntimeException: Exception in Application start method
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.launchApplication1(LauncherImpl.java:900)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication$2(LauncherImpl.java:195)
    at java.base/java.lang.Thread.run(Thread.java:834)
Caused by: MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player! : com.sun.media.jfxmedia.MediaException: Could not create player!
    at javafx.media/javafx.scene.media.MediaException.exceptionToMediaException(MediaException.java:146)
    at javafx.media/javafx.scene.media.MediaPlayer.init(MediaPlayer.java:518)
    at javafx.media/javafx.scene.media.MediaPlayer.<init>(MediaPlayer.java:421)
    at Test.MediaTest.start(MediaTest.java:18)
    at javafx.graphics/com.sun.javafx.application.LauncherImpl.lambda$launchApplication1$9(LauncherImpl.java:846)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runAndWait$12(PlatformImpl.java:455)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$10(PlatformImpl.java:428)
    at java.base/java.security.AccessController.doPrivileged(Native Method)
    at javafx.graphics/com.sun.javafx.application.PlatformImpl.lambda$runLater$11(PlatformImpl.java:427)
    at javafx.graphics/com.sun.glass.ui.InvokeLaterDispatcher$Future.run(InvokeLaterDispatcher.java:96)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
    at javafx.graphics/com.sun.glass.ui.gtk.GtkApplication.lambda$runLoop$11(GtkApplication.java:277)
    ... 1 more
Caused by: com.sun.media.jfxmedia.MediaException: Could not create player!
    at javafx.media/com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:295)
    at javafx.media/com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:118)
    at javafx.media/javafx.scene.media.MediaPlayer.init(MediaPlayer.java:474)
    ... 11 more
Exception running application Test.MediaTest

Here is the code:

import javafx.application.Application;
import javafx.scene.Scene;
import javafx.scene.layout.Pane;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.Stage;

public class MediaTest extends Application{
    private static final String MEDIA_URL = "file:///home/michael/eclipse-workspace/JFXTest/VideoExample.mp4";
    @Override
    public void start(Stage stage) throws Exception {
        Pane pane = new Pane();
        pane.setPrefSize(640, 480);
        Media media = new Media(MEDIA_URL);
        MediaPlayer mediaPlayer = new MediaPlayer(media);
        mediaPlayer.setOnReady(new Runnable(){
            @Override
            public void run() {
                System.out.println(media.getWidth() +" x "+ media.getHeight() +" : "+ media.getDuration());
                mediaPlayer.play();
            }
        });
        Scene scene = new Scene(pane, 640, 480);
        MediaView mediaView = new MediaView(mediaPlayer);
        pane.getChildren().add(mediaView);
        stage.setTitle("Why it doesn't work?");
        stage.setScene(scene);
        stage.show();
    }
    public static void main(String[] args) {
        launch();
    }
}

I know there are some questions on Stackoverflow regarding this issue, but none of them (the ones I found and checked) helps me.

I tried:

  • new Media(new File(MEDIA_URL).toURI().toString()) instead of new Media(MEDIA_URL)
  • Java tutorial default http://download.oracle.com/otndocs/products/javafx/oow2010-2.flv instead of local video
  • Running on OpenJFX 11 and 15
  • Adding jmods
  • Installing GStreamer (as noted in JavaFX 1.2 SDK Requirements )
  • I have libavcodec58 and libavformat58 (as noted in JavaFX 2 Certified System Configurations
  • I have GLIB 2.31 (Ubuntu GLIBC 2.31-0ubuntu9.2)

I have no ideas what else I could be missing or done wrong. I would be grateful for any help!

The problem resolved itself (Hmm?).

  1. I added JavaFX jmod s instead of jar s and recompiled => didn't work;
  2. Added JavaFX 16 (EA) to the classpath and then removed => it worked, weird...

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM