public class tab2 extends Fragment {
private Button play,stop,record;
private MediaRecorder myAudioRecorder;
private String outputfile;
public tab2() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
// Inflate the layout for this fragment
final View rootview=inflater.inflate(R.layout.fragment_tab2,container,false);
Button record=(Button)rootview.findViewById(R.id.record);
File directorysample=new File(Environment.getExternalStorageDirectory()+separator+"CallRecords");
directorysample.mkdirs();
String filename = "/recording_" + System.currentTimeMillis() + ".mp3";
final String directory = Environment.getExternalStorageDirectory()+ "/CallRecords";
outputfile = directory + "/" + filename;
record.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
try {
myAudioRecorder=new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.VOICE_CALL);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT);
//myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.DEFAULT);
myAudioRecorder.setOutputFile(outputfile);
myAudioRecorder.prepare();
myAudioRecorder.start();
}
catch (IllegalStateException ise){
}catch (IOException ioe){
}
}
});
return rootview;
}
}
答案 0 :(得分:0)
如果您的文件使用0kb创建,那么您可以尝试关注记录文件。
myAudioRecorder = new MediaRecorder();
myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
myAudioRecorder.setOutputFile(outputFile);
myAudioRecorder.prepare();
myAudioRecorder.start();