Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/207.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android 录制的文件无法播放_Android_Mediarecorder - Fatal编程技术网

Android 录制的文件无法播放

Android 录制的文件无法播放,android,mediarecorder,Android,Mediarecorder,我计划创建一个通话记录应用程序,下面我展示了代码,在我按下录制按钮进行通话后,应用程序在存储器中创建了一个文件,但mp3播放器没有播放该文件,我想知道我应该做什么更改 public class tab2 extends Fragment { private Button play,stop,record; private MediaRecorder myAudioRecorder; private String outputfile; public tab2() { // Requir

我计划创建一个通话记录应用程序,下面我展示了代码,在我按下录制按钮进行通话后,应用程序在存储器中创建了一个文件,但mp3播放器没有播放该文件,我想知道我应该做什么更改

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;
}

}

如果您的文件创建为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();

到底怎么了?你收到错误信息了吗?这只是创建0kb的文件我不想只捕获麦克风,我想录制通话