Search code examples
javajavafxnetbeans-8.1

JavaFX Media Exception. Could not create player


I've been trying to make a simple GUI player in Java with JavaFX. It works fine until i try to open a file. It just throw a stack and do nothing.

STACK

Executing /home/julius/Templates/Java-Projects/JavaFXApplication1/dist/run1593625829/JavaFXApplication1.jar using platform /usr/lib/jvm/java-8-openjdk-amd64/jre/bin/java
Prism-ES2 Error : GL_VERSION (major.minor) = 1.4

(java:4134): Gtk-WARNING **: Unable to locate theme engine in module_path: "adwaita",

(java:4134): Gtk-WARNING **: Unable to locate theme engine in module_path: "adwaita",

FilePath is- file:///home/julius/Videos/MOVIES/SAW/sAw/Saw.mp4

Exception in thread "JavaFX Application Thread"  java.lang.RuntimeException: java.lang.reflect.InvocationTargetException
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1774)
at javafx.fxml.FXMLLoader$ControllerMethodEventHandler.handle(FXMLLoader.java:1657)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:86)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:49)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Node.fireEvent(Node.java:8413)
at javafx.scene.control.Button.fire(Button.java:185)
at com.sun.javafx.scene.control.behavior.ButtonBehavior.mouseReleased(ButtonBehavior.java:182)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:96)
at com.sun.javafx.scene.control.skin.BehaviorSkinBase$1.handle(BehaviorSkinBase.java:89)
at com.sun.javafx.event.CompositeEventHandler$NormalEventHandlerRecord.handleBubblingEvent(CompositeEventHandler.java:218)
at com.sun.javafx.event.CompositeEventHandler.dispatchBubblingEvent(CompositeEventHandler.java:80)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:238)
at com.sun.javafx.event.EventHandlerManager.dispatchBubblingEvent(EventHandlerManager.java:191)
at com.sun.javafx.event.CompositeEventDispatcher.dispatchBubblingEvent(CompositeEventDispatcher.java:59)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:58)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.BasicEventDispatcher.dispatchEvent(BasicEventDispatcher.java:56)
at com.sun.javafx.event.EventDispatchChainImpl.dispatchEvent(EventDispatchChainImpl.java:114)
at com.sun.javafx.event.EventUtil.fireEventImpl(EventUtil.java:74)
at com.sun.javafx.event.EventUtil.fireEvent(EventUtil.java:54)
at javafx.event.Event.fireEvent(Event.java:198)
at javafx.scene.Scene$MouseHandler.process(Scene.java:3757)
at javafx.scene.Scene$MouseHandler.access$1500(Scene.java:3485)
at javafx.scene.Scene.impl_processMouseEvent(Scene.java:1762)
at javafx.scene.Scene$ScenePeerListener.mouseEvent(Scene.java:2494)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:381)
at com.sun.javafx.tk.quantum.GlassViewEventHandler$MouseEventNotification.run(GlassViewEventHandler.java:295)
at java.security.AccessController.doPrivileged(Native Method)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.lambda$handleMouseEvent$2(GlassViewEventHandler.java:417)
at com.sun.javafx.tk.quantum.QuantumToolkit.runWithoutRenderLock(QuantumToolkit.java:389)
at com.sun.javafx.tk.quantum.GlassViewEventHandler.handleMouseEvent(GlassViewEventHandler.java:416)
at com.sun.glass.ui.View.handleMouseEvent(View.java:555)
at com.sun.glass.ui.View.notifyMouse(View.java:937)
at com.sun.glass.ui.gtk.GtkApplication._runLoop(Native Method)
at com.sun.glass.ui.gtk.GtkApplication.lambda$null$5(GtkApplication.java:139)
at java.lang.Thread.run(Thread.java:748)
Caused by: java.lang.reflect.InvocationTargetException
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.Trampoline.invoke(MethodUtil.java:71)
at sun.reflect.GeneratedMethodAccessor1.invoke(Unknown Source)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at sun.reflect.misc.MethodUtil.invoke(MethodUtil.java:275)
at javafx.fxml.FXMLLoader$MethodHandler.invoke(FXMLLoader.java:1769)
... 48 more
Caused by: MediaException: UNKNOWN : com.sun.media.jfxmedia.MediaException: Could not create player! : com.sun.media.jfxmedia.MediaException: Could not create player!
at javafx.scene.media.MediaException.exceptionToMediaException(MediaException.java:146)
at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:511)
at javafx.scene.media.MediaPlayer.<init>(MediaPlayer.java:414)
at javafxapplication1.FXMLDocumentController.handleButtonAction(FXMLDocumentController.java:47)
... 58 more
Caused by: com.sun.media.jfxmedia.MediaException: Could not create player!
at com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:274)
at com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:118)
at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:467)
... 60 more
Deleting directory /home/julius/Templates/Java-Projects/JavaFXApplication1/dist/run1593625829
jfxsa-run:
BUILD SUCCESSFUL (total time: 58 seconds)

[EDIT-1]

package javafxapplication1;


import java.io.File;
import java.net.
import java.util.ResourceBundle;
import javafx.application.Platform;
import javafx.beans.binding.Bindings;
import javafx.beans.property.DoubleProperty;
import javafx.event.ActionEvent;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.media.Media;
import javafx.scene.media.MediaPlayer;
import javafx.scene.media.MediaView;
import javafx.stage.FileChooser;

public class FXMLDocumentController implements Initializable {
private String filePath;

@FXML
private MediaPlayer mp;
@FXML
private MediaView mv;
@Override
public void initialize(URL arg0, ResourceBundle arg1) {}

@FXML
public void handleButtonAction(ActionEvent event) {
    FileChooser fc= new FileChooser();
    FileChooser.ExtensionFilter extensionFilter= new FileChooser.ExtensionFilter("Video files with mp4 extension only.", "*.mp4");
    fc.getExtensionFilters().add(extensionFilter);
    
    File file= fc.showOpenDialog(null);
    filePath= file.toURI().toString();
            
    if(filePath!= null) {
                System.out.println("FilePath is- "+filePath);
        Media media= new Media(filePath);
        mp= new MediaPlayer(media);
        mv.setMediaPlayer(mp);
        DoubleProperty width= mv.fitWidthProperty();
        DoubleProperty height= mv.fitHeightProperty();
        width.bind(Bindings.selectDouble(mv.sceneProperty(), "width"));
        height.bind(Bindings.selectDouble(mv.sceneProperty(), "height"));
        mp.play();
    }
}

@FXML public void playButton(ActionEvent event) {mp.play(); mp.setRate(1);}
@FXML public void pauseButton(ActionEvent event) {mp.pause();}
@FXML public void stopButton(ActionEvent event) {mp.stop();}
@FXML public void forwardButton(ActionEvent event) {}
@FXML public void rewindButton(ActionEvent event) {}
@FXML public void fasterButton(ActionEvent event) {mp.setRate(2);}
@FXML public void slowerButton(ActionEvent event) {mp.setRate(0.5);}
@FXML public void exitButton(ActionEvent event) {Platform.exit();}
}

The path seems alright and i can't figure there's anything wrong with my controller source let me know if anyone want to see the source. How can i fix this unknown Exception ?

Several things to keep in mind

  • Java version is

    openjdk version "1.8.0_151"

    OpenJDK Runtime Environment (build 1.8.0_151-8u151-b12-0ubuntu0.17.10.2-b12)

    OpenJDK 64-Bit Server VM (build 25.151-b12, mixed mode)

  • I'm using Netbeans IDE with all javafx plugins installed.


Solution

  • Sorted this out by installing Java 9.0.4 and Intellij IDE. Netbeans 8.2 isn't compatible with java 9. The code was all right.

    UPDATED CODE

    The controller source has been updated to make it compatible with java9. For some reason java.nio.file.Paths; isn't working with the latest java.