I am developing voice application.
I need a buffer queue of some sort so that i record continuosly in a thread , place the buffers full of bytes into the queue and to transmit to the server, and i take the next buffer from the queue.
Here is the recording code:
Queue<byte[]> qArray = new LinkedList<byte[]>();
recordingThread = new Thread(new Runnable() {
@Override
public void run() {
bData = new byte[BufferElements];
while (isRecording) {
recorder.read(bData, 0, BufferElements);
qArray.add(bData);
if (AudioRecord.ERROR_INVALID_OPERATION != 0) {
SendAudio();
}
}
}
}, "AudioRecorder Thread");
recordingThread.start();
But still its missing few of byte[] data while sending it to the server
Here is the sending voice to the server code:
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httppost = new HttpPost(ServerUrl.url_audio);
// Json Format
JSONObject holder = new JSONObject();
JSONArray jArray = new JSONArray();
try {
byte[] tmparr = qArray.poll();
for (int i = 0; i < tmparr.length; i++) {
jArray.put(i, tmparr[i]);
}
holder.put("Voice", jArray);
I dont want to miss any data which is recording.
Any help would be appreciated lot. Thanks