我想验证 voice_call 的音频源是否可用:
MediaRecorder.AudioSource.VOICE_CALL
由于某些设备不允许,如何检查我是否可以以编程方式记录电话?
提前致谢。
科比
我想验证 voice_call 的音频源是否可用:
MediaRecorder.AudioSource.VOICE_CALL
由于某些设备不允许,如何检查我是否可以以编程方式记录电话?
提前致谢。
科比
检查的方法是尝试记录并捕获异常。没有人想出任何其他方法来提前知道该设备是否可以工作。如果您发现异常,您可以尝试从 MediaRecorder.AudioSource.MIC 开始录制。如果手机的喇叭声音小,你会发现只有手机的主人会被录音,而线路上的对方不会,但这是你能做的最好的了。
我还没有看到禁用这些功能的手机型号列表。这肯定是一个方便的清单。
我认为您可以改用 MediaRecorder.AudioSource.MIC。
我做了这个过程:我尝试在我想要的形状的 try / catch 块中创建一个文件,在开始和停止记录器时,一切顺利,它与选定的音频源一起工作。
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) {
}
};
}