I absolutely can't find the reason why my program doesn't quit.
It is one of the examples in the book 'Head First Java'.
This is 'my' code:
Everything seems to work fine, it plays the sound as expected and obviously also jumps back to main, because the terminal also shows the message which I have entered for debugging, 'System.out.println("after mini.play");' at the end of main.
But then - the program never quits and the terminal stands there waiting forever.
The problem occurs on my Ubuntu Linux computer as well as on another one with XP on it. For this reason I think that I made a mistake which I am simply not able to find.
You need to close() the Sequencer. Without that it still has a running thread somewhere. The issue is when to close it, though. You should wait for an event that signals the playing is done. Now that's usually where ControllerEventListener is for, but my tests haven't been able to get it to really listen.
You can use the isRunning() method on player to check when it's done.
Joined: Jan 22, 2010
Thank you so much for your replies. Without them I never would have found the error.
They really should have mentioned in the book that this behaviour will occur - I double checked the code in the book, but there is definitely no close() method used.
Well - now it works, even so my solution is probably bad style!?
Btw.: while browsing through the API my first idea also was to use the isRunning() method, but that didn't work. I guess that it stays true until the sequencer's close() method is called what will never happen in this case.
That's how I used it: