How do you play audio data contained in a byte[]?

John Zukowski

The Java Sound API contains support for playing byte arrays. Given that this question was submited to the Applets FAQ, I'm assuming you're not using a Java runtime new enough to support that. If you are using a runtime derived from Sun, there is a package you can try to use. It is available to IE and Netscape. Something like the following should work, though I haven't tried this in some time:

AudioData audiodata = new AudioData(byteArray);
AudioData audioData = new AudioStream(url.openStream()).getData();
AudioDataStream audioStream = new AudioDataStream(audioData);
// play()
// loop()
ContinuousAudioDataStream continuousStream = 
  new ContinuousAudioDataStream(audioStream);

If you grab the code for my AWT book from O'Reilly, you'll find a SunAudioClip class that implements java.applet.AudioClip for you.
About | Sitemap | Contact