1

When I run my method, I get a MediaException. I call the method with playSound("src/assets/timeup.mp3");.

private void playSound(String path) {
        System.out.println(path);
        Media hit = new Media(new File(path).toURI().toString());
        System.out.println(hit.getSource());
        MediaPlayer mediaPlayer = new MediaPlayer(hit);
        mediaPlayer.play();
    }

Log:

src/assets/timeup.mp3
file:/media/chris/1%20TB%20Data/Eclipse/workspace/DrEggTimer/src/assets/timeup.mp3
Exception in thread "main" 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 timer.Timer.playSound(Timer.java:53)
    at timer.Timer.<init>(Timer.java:58)
    at timer.Timer.main(Timer.java:39)
Caused by: com.sun.media.jfxmedia.MediaException: Could not create player!
    at com.sun.media.jfxmediaimpl.NativeMediaManager.getPlayer(NativeMediaManager.java:222)
    at com.sun.media.jfxmedia.MediaManager.getPlayer(MediaManager.java:104)
    at javafx.scene.media.MediaPlayer.init(MediaPlayer.java:467)
    ... 4 more

My project is on an external drive and I am linking it to my main drive with a symlink. I am running Eclipse on the main drive. I don't believe that should cause any problems though.

1 Answers1

2

If you are on linux (which it appears you are from your stacktrace). You need to install libavformat53 and libavcodec53 for javafx's MediaPlayer to work, else you will get that error.

randomlinuxmod
  • 327
  • 4
  • 12
  • How do you do that on Fedora? (Seems like maybe you could answer your own question now: http://stackoverflow.com/questions/27475902/fedora-21-javafx-not-creating-mediaplayer ) – Travis Well Sep 12 '16 at 22:51
  • On fedora it's a bit tricky. I needed to manually find and install libavcodec53 and all of it's dependency rpms as previous versions of the libav libraries are no longer included in the official repositories. – randomlinuxmod Oct 09 '16 at 17:43