• Post Reply Bookmark Topic Watch Topic
  • New Topic

Saving a sound as byte array  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hello there everyone,

Hopefully writing this post won't be a waste of my time or your time in reading it.
I am able to play sounds from a file using...(try catch blocks omitted for clarity)


Now, I can turn the file into bytes using..

And printing out data shows it has been read into.

So what I would like to do is play a sound given a byte[]
I attempted this..., but did not work.

But this does not work, can anyone help me to fix this?

Thanks very much.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But this does not work:Are you not able to hear sound or getting an exception ?

Streams are also pipes of bytes.Though I have not worked with sound in Java.But I think that if you read the bytes from inputstream to byte array and again convert the byte array into a stream.It should be fine , nothing wrong.
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, good point, I put a print out in the catch block, and so

Is throwing an error with message
"could not create audio stream from input stream"

Any idea how I can fix this?
Thanks
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!