A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Win a copy of
Refactoring for Software Design Smells: Managing Technical Debt
this week in the
OO, Patterns, UML and Refactoring
Java in General
Saving sound as byte array
Joined: Apr 11, 2005
Jul 21, 2007 06:51:00
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
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link:
subject: Saving sound as byte array
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
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2015