Android 在音乐中找不到新创建的声音文件

Android cannot find the new created sound file in music

我创建了一个文件并用它来保存我的声音文件,但是这个文件不能添加到音乐中

File f;
boolean recording=false;
public void startStopRecording(View view){

    try {

        if (!recording) {
            do {
                DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
                Date date = new Date();
                String filename = "rec_" + dateFormat.format(date)+".gpp";
                outputFile = Environment.getExternalStorageDirectory().getAbsolutePath() + "/myRec/"+filename;
                f = new File(outputFile);
                f.getParentFile().mkdirs();

            }while(f.exists());
            myAudioRecorder = new MediaRecorder();
            myAudioRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
            myAudioRecorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
            myAudioRecorder.setAudioEncoder(MediaRecorder.OutputFormat.AMR_NB);
            myAudioRecorder.setOutputFile(outputFile);
            myAudioRecorder.prepare();
            myAudioRecorder.start();
            recording=!recording;
        }else{
            myAudioRecorder.stop();
            myAudioRecorder.release();
            myAudioRecorder  = null;
            recording=!recording;

            Intent mediaScanIntent = new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE);
            mediaScanIntent.setData(Uri.fromFile(f));
            sendBroadcast(mediaScanIntent);
            MediaScannerConnection.scanFile(this, new String[]{f.getAbsolutePath()}, null, null);
        }
    }  catch (IOException e) {
        e.printStackTrace();
    }

}

这个我也试过了,还是不行

ContentValues values = new ContentValues(4);
long current = System.currentTimeMillis();
values.put(MediaStore.Audio.Media.TITLE, "audio file");
values.put(MediaStore.Audio.Media.DATE_ADDED, (int) (current / 1000));
values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/3gpp");
values.put(MediaStore.Audio.Media.DATA, f.getAbsolutePath());
ContentResolver contentResolver = getContentResolver();
Uri base = MediaStore.Audio.Media.EXTERNAL_CONTENT_URI;
Uri newUri = contentResolver.insert(base, values);
sendBroadcast(new Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, newUri));

如何将我的声音文件添加到音乐?

替换

 String filename = "rec_" + dateFormat.format(date)+".gpp";

String filename = "rec_" + dateFormat.format(date)+".3gp";

可以参考这个教程

http://www.tutorialspoint.com/android/android_audio_capture.htm

如果您仍然觉得有问题,请下载此示例

https://github.com/hiteshsahu/Android-Audio-Recorder-Visualization-Master