0

我正在通过媒体播放器保存一些录音:

private void startrecording() {

        audiofile = getAudiofile();
        if (audiofile != null)
            myaudiorecoreder = new MediaRecorder();
        myaudiorecoreder.setAudioSource(MediaRecorder.AudioSource.MIC);
        myaudiorecoreder.setOutputFormat(MediaRecorder.OutputFormat.MPEG_4);
        myaudiorecoreder.setOutputFile(audiofile.getAbsolutePath());
        myaudiorecoreder.setAudioEncoder(MediaRecorder.AudioEncoder.AAC);
        try {
            myaudiorecoreder.prepare();
            setRecordstatus(true);

        } catch (IllegalStateException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        myrecordtextview.setText("RECORDING STARTED..SPEAK NOW");
        myaudiorecoreder.start();

//其中audiofile将给出声音文件。这是我从中获取文件(空)的getAudiofile()的代码。//

private File getAudiofile() {
        String extState = Environment.getExternalStorageState();
        if (extState.equals(Environment.MEDIA_MOUNTED)) {
            File mediaStorageDir = new File(
                    Environment.getExternalStorageDirectory() + "/TAUKY/AUDIO");
            if (!mediaStorageDir.exists()) {
                if (!mediaStorageDir.mkdirs()) {
                    Log.e("SDCARD", "failed to create directory");
                    Toast.makeText(getApplicationContext(),
                            "FAILED TO CREATE DIR", 0).show();
                    return null;
                }
            }
            String timeStamp = new SimpleDateFormat("yyyyMMdd_HHmmss")
                    .format(new Date());
            mediaFile = new File(mediaStorageDir.getPath() + File.separator
                    + "SOUND_" + timeStamp + ".mp3");
            // Toast.makeText(getApplicationContext(), "FILE CREATION DONE",
            // 0).show();

        } else {
            Toast.makeText(getApplicationContext(), "NO SDCARD", 0).show();
        }
        return mediaFile;
    }

现在在下一个活动中如何从 sdcard 的特定文件夹中检索,即 /TAUKY/AUDIO 谢谢

4

1 回答 1

1

您的问题不是很清楚,但是如果您想在将文件保存在 sdcard 后播放文件,您可以执行类似的操作,因为您知道文件的路径。

FileDescriptor fd = null;
File baseDir = Environment.getExternalStorageDirectory();
String audioPath = baseDir.getAbsolutePath() + /TAUKY/AUDIO/SOUND_ + timeStamp + ".mp3";
FileInputStream fis = new FileInputStream(audioPath);
fd = fis.getFD();

MediaPlayer mediaPlayer = new MediaPlayer();
mediaPlayer.setDataSource(fd);
mediaPlayer.prepare();
mediaPlayer.start();

我不能 100% 确定,因为我无法测试它,但它应该是这样的。希望这可以帮助。

于 2013-02-06T17:12:58.563 回答