I'm using a SwingWorker to seperate a loop in my code which plays a midi sound. However I need to use the SwingWorker more than once and there's no way of telling how many times it will need to be repeated as its executed on a button click.
Here is the method which uses the SwingWorker:
I understand that doInBackground() can only be executed once but here I am making a new object every time that button is pressed (playTune() is fired when the button is clicked). Equally I should mention that there is a stop button which turn stopTune to true when it is clicked. Any help would be much appreciatedCode:public void playTune() { //Play tune swing worker SwingWorker<TunePlayer, Void> playWorker = new SwingWorker<TunePlayer, Void>() { @Override protected TunePlayer doInBackground() throws Exception { while (!stopTune) { if (!player.isPlaying()) { player.play(tune); } } return null; } }; playWorker.execute(); }




Reply With Quote