troubleshooting Question

JAudiorecorder record freezing the app

Avatar of dolphin King
dolphin King asked on
Delphi
29 Comments1 Solution265 ViewsLast Modified:
i am trying to use jaudiorecorder to record sound to a stream from android but while recorder and start sending buffer the app is completley freeze any idea why ?

here is the current code

//audio recorder 
GBUFFSIZE := TJAudioRecord.JavaClass.getMinBufferSize(8000,
TJAudioFormat.JavaClass.CHANNEL_IN_MONO,
TJAudioFormat.JavaClass.ENCODING_PCM_16BIT);

Gstream := TJavaArray<Byte>.Create(GBUFFSIZE);

AudioRecorder:= TJAudioRecord.JavaClass.init(TJMediaRecorder_AudioSource.JavaClass.VOICE_COMMUNICATION,
8000,
TJAudioFormat.JavaClass.CHANNEL_IN_MONO,
TJAudioFormat.JavaClass.ENCODING_PCM_16BIT,
GBUFFSIZE);


//start recording

(AudioRecorder as JAudioRecord).startRecording;
papulaterecorder.Enabled := True;

//timer
procedure TForm1.papulaterecorderTimer(Sender: TObject);
var
  index: Integer;
  NewCount: Integer;
  Bytes: TIdBytes;
begin


// Read from the AudioRecover
NewCount:= (AudioRecorder as JAudioRecord).read(Gstream, 0, GBUFFSIZE);
if  (NewCount > 0) then
begin
Bytes := RawToBytes(Gstream.Data^, NewCount);
SendBuffer(Bytes, NewCount);
end;

end;


end;


procedure SendBuffer(Buffer: TIdBytes; BufferSize: Cardinal);
Var
Strm: TIdMemoryBufferStream;
begin

Strm := TIdMemoryBufferStream.Create(PByte(Buffer), BufferSize);
try
FTCP.Socket.WriteLn('stream');
FTCP.Socket.LargeStream := True;
FTCP.Socket.Write(Strm, 0, True);
finally
Strm.Free;
end;
end;
ASKER CERTIFIED SOLUTION
Sinisa Vuk
Software architect
Join our community to see this answer!
Unlock 1 Answer and 29 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 1 Answer and 29 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros