我试图通过直接调用android api TJAudioRecord来记录firemonkey中的音频,但它不起作用,audioRecord.getState返回STATE_UNINITIALIZED,无论我尝试过,请帮忙吗?
此功能有一些错误
audioRecord :=
TJAudioRecord.JavaClass.init(TJMediaRecorder_AudioSource.JavaClass.VOICE_COMMUNICATION,
16000,
TJAudioFormat.JavaClass.CHANNEL_IN_MONO,
TJAudioFormat.JavaClass.ENCODING_PCM_16BIT,
bufferSize);
完整代码
bufferSize := TJAudioRecord.JavaClass.getMinBufferSize(16000,
TJAudioFormat.JavaClass.CHANNEL_IN_MONO,
TJAudioFormat.JavaClass.ENCODING_PCM_16BIT);
if (bufferSize <> TJAudioRecord.JavaClass.ERROR_BAD_VALUE) then
begin
audioRecord := TJAudioRecord.JavaClass.init(TJMediaRecorder_AudioSource.JavaClass.VOICE_COMMUNICATION,
16000,
TJAudioFormat.JavaClass.CHANNEL_IN_MONO,
TJAudioFormat.JavaClass.ENCODING_PCM_16BIT,
bufferSize);
ShowMessage(IntToStr(buffersize));
if (audioRecord.getState = TJAudioRecord.JavaClass.STATE_INITIALIZED)then begin
//then begin
audioRecord.startRecording;
ShowMessage('ok');
end;
end;
except
ShowMessage('Error 0');
end;
答案 0 :(得分:1)
我使用以下代码,它适用于我的三星Galaxy Note III。
Ses := TJAudioRecord.JavaClass.init(TJMediaRecorder_AudioSource.JavaClass.MIC, 11025, TJAudioFormat.JavaClass.CHANNEL_IN_MONO, TJAudioFormat.JavaClass.ENCODING_PCM_16BIT, 44100 * 2);
(Ses As JAudioRecord).startRecording;
Okunan := 0;
M := TMemoryStream.Create;
for I := 1 to 2 do
Begin
Tampon := TJavaArray<SmallInt>.Create(44100);
Okunan := Okunan + (Ses As JAudioRecord).read(Tampon, 0, 44100);
M.Write(Tampon.Data^, Tampon.Length * 2);
Tampon.Free;
End;
(Ses As JAudioRecord).stop;
Ses.release;
M.SaveToFile(TPath.GetRingtonesPath+'/ses.raw');