I have tried a couple different things to get sound out of an applet program I am writing as a project. I do have it all working, but not the way I want it to work.

To get sound, I am using sun.audio.AudioPlayer because that seems to be the only thing I can find in Java that allows me to play a series of applet generated tones (morse code) that are included in a stream. Basically, the applet takes user text input, translates it to its visual morse equiv. (dots and dashes) then parses the output text of dots and dashes and creates a stream (byte stream) that is played through AudioPlayer.player.start(stream).

Now, here is where I ran into problems...

As the applet stands now, the user enters text, hits start, and as long as user does not hit the stop button, the applet translates the full user text, creates a stream based on the full output text (the converted user input), and plays that stream through AudioPlayer at a given speed (user selects character speed to create fast or slow Morse Code).

However, what I WANTED to do, was have it play back the Morse code one character at a time, as it writes it to output. So basically, there is a bit of code like this:

Code:
for (i = 0; i < morsetext.lenght; i++) {
   if (visualOutput) {  //visualOutput is a boolean to tell us if that option is checked
      textPanelOutput.setText(textPanelOutput.getText() + morsetext[i]);
   }
   if (audibleOutput) { //audibleOutput is a boolean to tell if audio output option is checked
      stream = createStream(moresetext[i],wpm); //wpm is the char speed
      sunAudioPlayer.player.start(stream)
   }
}
That actually works, except for one issue... What ends up happeneing is that, say morsetext[] contains 5 character representations (each item in morsetext[] is a string of dots and dashes representing the morse code version of a text character), the program generates the stream for character morsetext[0] and starts the player for it, then goes back into the loop and does the same for morsetext[1], and on and on to the end of the array. The applet, in this setup, ends up playing the streams for all the characters simultaneously, instead of one at a time.

What I wanted originally, was to have it do somethig like this, in poor pseudocode:
(assume all other work is done. user input is captured and translated. Each char is placed in an array, and is ready to be outputted)

Code:
Start Loop
  get first item in morsetext[]
    create stream from that item
    return stream from createStream function
    append that item (from morsetext[x]) to output textpanel
    start audioplayer with that stream
    wait until stream finishes
    increment counter and proceed to next loop iteration
end loop
That way, for each character of user input, the applet will print the morse equiv. to a visual text panel, and play the output audibly, BEFORE moving to the next character that the user entered.

But, like I said, if I do this, right now, the program does loop properly, and does everything properly, but does not wait for the previous stream to finish before starting the next.
Right now I have it set so that it outputs the full translated string to the text panel, adn then plays the full string as morse code sounds... but I think it would look better doing it one letter at a time.

Any suggestions on finding the state of sun.audio.AudioPlayer and ensuring that the program does not continuse the playback loop until the player has finished the current stream it is playing??

In any case, I have a working program that I can turn in, and I know that the prof will be ticked with it, BUT, being the kind of person that I am, I won't feel right in turning it in until it does exactly what I wanted it to do in the first place...

And yes, I could try some other method for producing sound, but I cant find any other way that gives as much control as this method does... the rest seem focused on playing files, rather than generating the sounds on the fly.

Oh well... I would love to hear any thoughs on this...

Cheers
Jeff