09-25-2012 08:48 AM
I recod sound aon "capture://audio?encoding=audio/amr" and stored the byte array of this on database then I read the hole byte array on xml
I stored it's value on string so my string containe the byte array value it will work. Then I convert the string value to byte array from string.getBytes() method
I place the following code on button click but it not start the playing of the byte array. and I not get any sound
Dialog.alert("start Audio "+audio_value);
input = new ByteArrayInputStream(audio_value);
SOP("input -7 " +audio_value.length);
_player = Manager.createPlayer(input, "audio/amr");
VolumeControl volume = (VolumeControl)_player.getControl("VolumeControl")
Can any one provide sample code for playing audio file from byte array. and how to play from datasource plz
Thanks in advance
09-25-2012 10:28 AM
Your approach of converting the byte array to a Stream and playing that is correct, I have different cod that does much the same sort of thing.
I don't understand this:
"stored it's value on string so my string containe the byte array value it will work."
sounds should not be converted to Strings - Strings are sequences of characters, but sounds files are bytes that have no validity when interpreted as characters. I suspect there is a problem in this part of the processing. Se if you can keep the sound file as bytes and never convert it to a String, and that might help.
The other thing I would try is to add a resource to your project and use that file as input rather than your one - that will test to see of your player is working correctly - if so, then the problem is in the file creatin/conversion.
09-26-2012 01:54 AM
09-26-2012 04:44 AM
I assume that you have in fact tried your audio playback code with a byte array that you know to be working, which means the problem is in the conversion of the bytes to String (characters) and back again.
This is actually a common problem. There are a variety of ways of converting bytes if you intend to treat the bytes as characters and the common problem is that when converting to String, most people do new String(<bytes>) and don't specify UTF-8 as the encoding, but the other end assumes UTF-8. So this is one thing that you could look at. Most Servers use UTF-8, the BlackBerry by default using ISO-8891-1 (from memory) but you can tell the BB to use UTF-8.
However the data you are storing is NOT character data, so while converting to character and converting back will mostly work, I'm not convinced it will always work. Personally when I am sending binary data that I know needs to treated as characters (as you do because it comes back in an XML stream), then I Base64 encode it. So you will send the Server the file Base64 encoded and then process the String you get back by Base 64 decoding it.
But the first step you need to do is to prove that this is the problem. So take a recording and note the exact byte values that you send to the Server. Then note the byte values you try to play when you get back from the Server what should be the same audio file. If you compare the bytes and they are not the same, then you have your problem.
Remember that to output the bytes you will need to use something to hex printt the byte values, so look for a byte array to Hex method - there are a few samples of this on the forum if you can't find something elsewhere.
09-26-2012 08:43 AM
can you tell me how to play a sound file from server
if (WLANInfo.getWLANState() == WLANInfo.WLAN_STATE_CONNECTED)
p = javax.microedition.media.Manager.createPlayer("http://www.oddfractions.com/sales_app/images/"+strAudio_file+";interface=wifi");
p = javax.microedition.media.Manager.createPlayer("http://www.oddfractions.com/sales_app/images/"+strAudio_file);
//Player p = Manager.createPlayer("http://www.oddfractions.com/sales_app/images/"+strAudio_file);
VolumeControl volume = (VolumeControl)p.getControl("VolumeControl");
SOP("Error @ AMR "+e);
this code give error
net.rim.device.internal.media.RimMediaException: Media unloaded while initializing
Can any one give the solution for this
Thanks In advance