I tried typing and compiling the example in ch 11 of Head First Java, which is a program that plays a note. When I run it, the command window frezes up as if the program won't stop running. Then I have to shut down the command window, start it all over again, and I don't think the program is supposed to do that. Here is the code:
This is pretty cool stuff, and I wish I didn't have to restart the command window, re-type in the directory, etc jsut to run the program! Is there any way to get around this? The program itself is pretty much copied word for word from the book.
I do know about while loops. I'm not sure how I would use one here though. The problem is that the command line window is freezing. If the command line window did not freeze, then I could put everything in a loop no problem. The program should play a note then terminate. Instead, it plays a note then freezes up. Even if I get rid of the player.start() line, it won't play a note, but it still freezes the command window, as if the program is not terminating somehow. Which leaves me to believe that it's not a problem with midi or anything like that, it's probabily just something in the code that I am not catching.
Joined: Jul 29, 2011
Well, I have messed around some more, and the problem is really that the program won't terminate when it is done. Everything else works. Does anyone have any insight as to why the program won't terminate? Here is my code so far:
As you can see, it just gets input from the user which is 2 numbers, then it calls the method play which plays the note with the given instrument, and it just keeps doing that until the user enters "Q" at the right time.
I'm looking at the same tutorial and was trying to figure out why i get no sound output. I get no compilation or runtime errors, but no sound is produced.
I'm guessing this might be machine specifc, but not sure where to start looking?
I've never used the sound stuff so I may be wrong but I would have thought it played sounds asynchronously in which case that would stop the player immediately, probably before it's even played any sound.
Calling player.close() once "Q" is pressed would be a good idea though.