title: JavaFX Media Player not working
body: <p>When I run this code, I get two exceptions. I have Java 8 installed correctly and it is the oracle version (NOT OpenJDK). This same code works fine and plays the media without any problems on Windows with Java 8. I do not want to use an Application because I am trying to play this media from more (Non-JavaFX) code.</p>
  
  <pre><code>import javafx.embed.swing.JFXPanel;
  import javafx.scene.media.Media;
  import javafx.scene.media.MediaPlayer;
  
  public class Test {
      public static void main(String[] args) {
          new JFXPanel();//Required to initialize JavaFX or I get this exception: Exception in thread "Thread-0" java.lang.IllegalStateException: Toolkit not initialized
          String fileLocation = "file:/home/chris/Music/jawstheme.mp3";
          System.out.println(fileLocation);
          Media hit = new Media(fileLocation);
          MediaPlayer mediaPlayer = new MediaPlayer(hit);
          mediaPlayer.play();
      }
  }
  </code></pre>
  
  <p>And here is the exception I get.</p>
  
  <pre><code>file:/home/chris/Music/jawstheme.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.&lt;init&gt;(MediaPlayer.java:414)
      at Test.main(Test.java:11)
  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)
      ... 2 more
  </code></pre>