Search within Java in General
Register / Login
this forum made possible by our volunteer staff, including ...
Stephan van Hulst
Java in General
Saving sound as byte array
posted 15 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
Something must be done about this. Let's start by reading this tiny ad:
the value of filler advertising in 2021
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