android - Problem with audio -



android - Problem with audio -

in android app can record sound , save on phone/sdk. checked audible , clear when play on phone. size of sound file created 5.9kb(.amr format). next upload file server, stores sound on sql db. upload successful. when uploaded sound played, garbled...

in database store sound in column datatype image , of length 16.

my question ..why noise garbled after upload. how verify sound saved correctly without noise added.

code file upload

inputstream = new datainputstream(new fileinputstream( filename)); byte[] responsedata = new byte[10000]; int length = 0; stringbuffer rawresponse = new stringbuffer(); while (-1 != (length = inputstream.read(responsedata))) rawresponse.append(new string(responsedata, 0, length)); string finalstring = rawresponse.tostring(); voicedataarray = finalstring.getbytes();

your problem much due utilize of stringbuffer buffer response. character in java two-byte entity corresponding unicode character point. documentation string#getbytes() says:

returns new byte array containing characters of string encoded using system's default charset.

so there's no guarantee bytes passing in, beingness converted characters, bytes same stream passed in first place.

i think need code solution using dynamically expanding byte buffer in place of stringbuffer.

also, 2 notes usage of stringbuffer:

1) accesses stringbuffer synchronized, you're paying performance penalty. stringbuilder modern-day replacement doesn't synchronization under hood.

2) each time append stringbuffer:

rawresponse.append(new string(responsedata, 0, length));

you allocating new string , throwing away. that's abusive garbage collector. stringbuffer has form of append() straight take char array, there no need utilize intermediate string. (but don't want utilize stringbuffer in first place).

android sql-server web-services audio-recording

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

intellij idea - Update external libraries with intelij and java -

javascript - send data from a new window to previous window in php -