我在6410的开发板上运行 Android 2.1,写了个程序 ,想要进行录音。代码 如下:
mediaRecorder = new MediaRecorder();
Toast.makeText(TelListenner.this,"new MedioRecorder()成功",
Toast.LENGTH_SHORT).show();
//myRecAudioFile = File.createTempFile("!"+MainActivity.strAddress1+MainActivity.strDate1, ".amr", dir);
myRecAudioFile=new File(dir,MainActivity.strAddress1+MainActivity.strDate1+"new.amr");
Toast.makeText(TelListenner.this,"createTempFile()成功",
Toast.LENGTH_SHORT).show();
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
Toast.makeText(TelListenner.this,"setAudioSource成功",
Toast.LENGTH_SHORT).show();
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
Toast.makeText(TelListenner.this,"setOutputFormat成功",
Toast.LENGTH_SHORT).show();
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
mediaRecorder.setOutputFile(myRecAudioFile.getAbsolutePath());//保存路径
Toast.makeText(TelListenner.this,"保存路径成功",
Toast.LENGTH_SHORT).show();
mediaRecorder.prepare();
Toast.makeText(TelListenner.this,"prepare成功",
Toast.LENGTH_SHORT).show();
mediaRecorder.start();
写了许多Toast,到
Toast.makeText(TelListenner.this,"保存路径成功",Toast.LENGTH_SHORT).show();
这一句还能弹出Toast,但是prepare()函数执行之后就不能弹出"prepare成功"的字样。
我查了一下prepare()函数的作用,是Prepares the recorder to begin capturing and encoding data。我怀疑是不是这个函数会调用底层硬件,而底层硬件可能有问题才导致的prepare()不运行??
另外,虽然File.createTempFile()这个函数执行了,但是在目录下面找不到建立的文件。这是因为什么?理论上讲,createTempFile()只要执行,就已经建立文件才对,虽然字节可能会是0,但是没理由文件都不存在啊。。。
这个问题困扰我两天了,求大神指导,万分感激~