3
回答
为什么电话录音得到的文件是空的
终于搞明白,存储TCO原来是这样算的>>>   

录音后相应目录下创建了.3gp文件,但大小为0。怎么回事?

public class PhoneRecordService extends Service {

	@Override
	public void onCreate() {
		TelephonyManager mgr = (TelephonyManager)getSystemService(Context.TELEPHONY_SERVICE);
		mgr.listen(new PhoneStateListener() {
			
			private MediaRecorder recorder = null;
			private String num = null;
			
			@Override
			public void onCallStateChanged(int state, String incomingNumber) {
				switch(state) {
				case TelephonyManager.CALL_STATE_RINGING:
					num = incomingNumber;
					break;
				case TelephonyManager.CALL_STATE_OFFHOOK:
					try {
						File dir = new File(Environment.getExternalStorageDirectory(), "record_phone");
						if(! dir.isDirectory())
							dir.mkdirs();
						File file = new File(dir, num + "_" + System.currentTimeMillis() + ".3gp");
						recorder = new MediaRecorder();
						recorder.setAudioSource(AudioSource.VOICE_CALL);//声音采集来源(话筒)
						recorder.setOutputFormat(OutputFormat.THREE_GPP);//输出的格式
						recorder.setAudioEncoder(AudioEncoder.AMR_NB);//音频编码方式
						recorder.setOutputFile(file.getAbsolutePath());//输出方向
						recorder.prepare();
						recorder.start();
					} catch (Exception e) {
						e.printStackTrace();
					}
					break;
				case TelephonyManager.CALL_STATE_IDLE:
					if (recorder != null) {
						recorder.stop();
						recorder.release();
					}
					break;
				}
			}
			
		}, PhoneStateListener.LISTEN_CALL_STATE);
		
		super.onCreate();
	}
	
	@Override
	public IBinder onBind(Intent arg0) {
		// TODO Auto-generated method stub
		return null;
	}

}

举报
leo-H
发帖于5年前 3回/634阅
顶部