I want to verify if the Audio source of voice_call is available:
MediaRecorder.AudioSource.VOICE_CALL
How to check if I can record phone calls programatically since some devices do not allow it?
thanks in advance.
Kobi
I want to verify if the Audio source of voice_call is available:
MediaRecorder.AudioSource.VOICE_CALL
How to check if I can record phone calls programatically since some devices do not allow it?
thanks in advance.
Kobi
The way to check is to try and record and catch the exception. No one has figured out any other way to know in advance if the device will work or not. If you catch the exception, you can try starting the recording from MediaRecorder.AudioSource.MIC. If the phone's speaker is low, you'll find that only the handset owner will be recorded and the other party on the line won't, but that's the best you can do.
I haven't seen a list of phone models that have these features disabled. It certainly would be a handy list to have.
I did this process: I try to create a file in a try / catch block in the shape I want, at the start and stop recorder, all goes well, it worked with the selected audiosource.
public class sRecAudioMic extends Service {
DecimalFormat fCoordenadas = new DecimalFormat("##.00000000");
DecimalFormat fVelocidade = new DecimalFormat("##.0");
static String imei = "";
private static String FORMATO_AUDIO = ".aac";
static String AUDIO_RECORDER_FOLDER = "";
static String codigo_usuario = "";
int contSegundos = 0;
static MediaRecorder recorder;
Boolean cancelTask = false;
eChamada chamada;
Context context;
public sRecAudioMic() {
}
@Override
public IBinder onBind(Intent intent) {
throw new UnsupportedOperationException("Not yet implemented");
}
@Override
public int onStartCommand(Intent intent, int flags, int startId) {
return super.onStartCommand(intent, flags, startId);
}
@Override
public void onCreate() {
imei = Functions.getIMEI(sRecAudioMic.this);
AUDIO_RECORDER_FOLDER = new _Path().getPathAudio();
}
@SuppressLint("InlinedApi")
@Override
public void onStart(Intent intent, int startId) {
try
{
Bundle b = intent.getExtras();
chamada = (eChamada) b.getSerializable("Chamada");
//chamada = (eChamada) intent.getParcelableExtra("Chamada");
String t = "";
t = " ";
}
catch(Exception e)
{
String t = "";
t = " ";
}
String nomeArquivo = "";
int cont = 0;
Calendar lCDateTime = Calendar.getInstance();
String t = String.valueOf(lCDateTime.getTimeInMillis());
nomeArquivo = "recording_" + t + FORMATO_AUDIO;
nomeArquivo = nomeArquivo.replace(" ", "_").replace(":", "_")
.replace("-", "_");
String caminhoArquivo = AUDIO_RECORDER_FOLDER + "/" + nomeArquivo;
chamada.nomeArquivo = nomeArquivo;
chamada.caminhoArquivo = caminhoArquivo;
try {
recorder = new MediaRecorder();
try {
MediaRecorder r = new MediaRecorder();
r.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
r.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
r.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
r.setOutputFile(caminhoArquivo);
r.setAudioSamplingRate(96000);
r.prepare();
r.start();
r.stop();
r.reset();
r.release();
r = null;
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
} catch (Exception e) {
MediaRecorder r = new MediaRecorder();
r.setAudioSource(MediaRecorder.AudioSource.MIC);
r.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
r.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
r.setOutputFile(caminhoArquivo);
r.setAudioSamplingRate(96000);
r.prepare();
r.start();
r.stop();
r.reset();
r = null;
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
}
recorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
recorder.setAudioSamplingRate(96000);
// recorder.setMaxDuration(30000);
recorder.setOutputFile(caminhoArquivo);
recorder.setOnErrorListener(errorListener);
recorder.setOnInfoListener(infoListener);
recorder.prepare();
recorder.start();
} catch (Exception e) {
e.printStackTrace();
new LOG().CriaLog("sRecAudioMic", "onStart()", e.getMessage(), "");
} finally {
}
}
@Override
public void onDestroy() {
String time = new java.text.SimpleDateFormat("dd/MM/yyyy HH:mm:ss")
.format(new java.util.Date());
if (null != recorder) {
// para gravacao
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
}
chamada.timestampChamadaTerminada = time;
ChamadasDataSource dsCham = new ChamadasDataSource(sRecAudioMic.this);
dsCham.open();
dsCham.insert(chamada);
dsCham.close();
}
@SuppressLint("NewApi")
private MediaRecorder.OnErrorListener errorListener = new MediaRecorder.OnErrorListener() {
@Override
public void onError(MediaRecorder mr, int what, int extra) {
}
};
@SuppressLint("NewApi")
private MediaRecorder.OnInfoListener infoListener = new MediaRecorder.OnInfoListener() {
@Override
public void onInfo(MediaRecorder mr, int what, int extra) {
}
};
}