Register / Login
Win a copy of
Clojure in Action
this week in the
Java in General
Saving sound as byte array
posted 8 years ago
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
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