Playing sound file not working
I tried out this video here: https://www.youtube.com/watch?v=ameD1ocbn9s
Now I want to change this, to play the file directly with java, with the javafx player:
String source = f.toURI().toString();
Media media = null;
media = new Media(source);
MediaPlayer mediaPlayer = new MediaPlayer(media);
But I get an "Toolkit not initialized" error. I cant figure out why this is happening?
Re: Playing sound file not working
I find out why this exception is thrown:
So which is the best way?
JavaFX performs "hidden" initialization on start. Running MediaPlayer doesn't trigger initialization.
The easiest ways to trigger it are:
have Application.launch() executed
have Application based program being run from jar packaged by fx ant tasks (e.g. built from Netbeans JavaFX project)
have JFXPanel started