Search within Java in General
Register / Login
Win a copy of
Terraform in Action
this week in the
this forum made possible by our volunteer staff, including ...
Stephan van Hulst
Java in General
Saving sound as byte array
posted 14 years ago
Number of slices to send:
Optional 'thank-you' note:
Hi I posted this question in the I/O streams section, but there was little response, and I have a little more info now:
I've ommitted try/catch blocks for clarity,
I am able to play a sound using...
File file=new File("res/sounds/sound1.wav"); InputStream is=new FileInputStream(file); AudioStream as=new AudioStream(is); AudioPlayer.player.start(as);
Now, I can turn the file into bytes using..
File file=new File("res/sounds/sound1.wav"); AudioInputStream ais=AudioSystem.getAudioInputStream(file); byte data=new byte[ais.available()]; ais.read(data);
So what I would like to do is play a sound given a byte
I attempted this..., but it threw an Exception
byte data=some array of bytes InputStream is=(InputStream)(new ByteArrayInputStream(data)); AudioStream as=new AudioStream(is); // THROWS EXCEPTION // AudioPlayer.player.start(as);
But AudioStram as=new AudioStream(is); throws an exception with message
-> "could not create audio stream from input stream"
Is there any way to solve this?
Thanks for any help
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
Boost this thread!
How do I loop the sound file in this program>
Audio format conversion problems
Saving a sound as byte array
Problem playing sound from application
Playing wav - java.io.FileNotFoundException when file is def there