I have an application written in Swing, in which I want to use JavaFX's MediaPlayer for playing audio / sound files.
This is a condensed version of the main file:
class MyApp
{
private MyApp myApp;
private JFrame myFrame;
private Media media;
private MediaPlayer mediaPlayer;
public static void main(String[] args)
{
Runnable thread = new Runnable()
{
public void run()
{
myApp = new MyApp();
}
};
SwingUtilities.invokeLater(thread);
}
public void MyApp()
{
//this is called by SwingUtilities.invokeLater();
URL url = //getting URL to a sound file stored locally//;
media = new Media(url.toString() );
mediaPlayer = new MediaPlayer( media );
mediaPlayer.play();
myFrame = new JFrame(); //building swing UI here
}
This seems to work within Netbeans. However when Netbeans builds a .jar, and I try to run the .jar, I get an error log file built in the .jar directory containing some memory / threading errors.
Do I need to use the Platform.runLater()
method to get this to work? Or is there anything else I'm doing wrong?