在 recorder.start();在4.2模拟器上启动录音时报错,不知道为何...在4.3上stop()报异常。
初次接触Android,请大神们指教
public class PhoneRecordService extends Service {
public void onCreate() {
super.onCreate();
Log.i(tag, "电话录音服务创建...");
TelephonyManager tm = (TelephonyManager) getSystemService(TELEPHONY_SERVICE);
tm.listen(new MyPhoneStatusListener(),
PhoneStateListener.LISTEN_CALL_STATE);
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public IBinder onBind(Intent intent) {
return null;
}
private class MyPhoneStatusListener extends PhoneStateListener {
private MediaRecorder recorder = null;
private String phoneNumber = null;
boolean isRecording = false;
@Override
public void onCallStateChanged(int state, String incomingNumber) {
super.onCallStateChanged(state, incomingNumber);
switch (state) {
case TelephonyManager.CALL_STATE_IDLE:// 闲置
if (null != recorder && isRecording) { //正在录音
recorder.stop();
recorder.reset(); // You can reuse the object by going back to setAudioSource() step
recorder.release(); // Now the object cannot be reused
recorder = null;
isRecording = false;
Log.i(tag, "结束录音..." + phoneNumber);
}
break;
case TelephonyManager.CALL_STATE_RINGING:// 响铃
phoneNumber = incomingNumber;
prepareRecorder();
Log.i(tag, "准备录音..." + phoneNumber);
break;
case TelephonyManager.CALL_STATE_OFFHOOK:// 接通
prepareRecorder();
if(!isRecording){
recorder.start(); // Recording is now started
isRecording = true;
Log.i(tag, "开始录音..." + phoneNumber);
}
break;
}
}
private void prepareRecorder() {
if(null == recorder){
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
recorder.setOutputFormat(MediaRecorder.OutputFormat.AMR_NB);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
String dirPath = FileUtils.createSDCardDir("/monitor");
recorder.setOutputFile(dirPath + System.currentTimeMillis() + "_" + phoneNumber + ".amr");
try {
recorder.prepare();
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
}
异常:
08-11 09:24:01.608: E/MediaRecorder(2412): start failed: -2147483648
08-11 09:24:01.618: D/AndroidRuntime(2412): Shutting down VM
对于start()方法的说明:
请教最后是怎么处理的呢?????、
是不是没有开启麦克风权限啊
版权声明:本文内容由阿里云实名注册用户自发贡献,版权归原作者所有,阿里云开发者社区不拥有其著作权,亦不承担相应法律责任。具体规则请查看《阿里云开发者社区用户服务协议》和《阿里云开发者社区知识产权保护指引》。如果您发现本社区中有涉嫌抄袭的内容,填写侵权投诉表单进行举报,一经查实,本社区将立刻删除涉嫌侵权内容。