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 sun.audio 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);
or 
AudioData audioData = new AudioStream(url.openStream()).getData();
AudioDataStream audioStream = new AudioDataStream(audioData);
// play()
AudioPlayer.player.start(audioStream);
// loop()
ContinuousAudioDataStream continuousStream = 
  new ContinuousAudioDataStream(audioStream);
AudioPlayer.player.start(continuousStream);

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.
0 Comments  (click to add your comment)
Comment and Contribute

 

 

 

 

 


(Maximum characters: 1200). You have 1200 characters left.

 

 

About | Sitemap | Contact