【问题标题】:Get Audio Recorded by RecorderAudio Activity获取 RecorderAudio Activity 录制的音频
【发布时间】:2011-12-29 18:44:58
【问题描述】:

我搜索了很多,但没有找到捕获Recorder Activity录制的音频的解决方案。

private void onClick() {
    Intent intent = new Intent();
    intent.setAction(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
    try {
        startActivityForResult(intent, IDF_ACTIVITY_AUDIO);
    } catch (ActivityNotFoundException e) {
    }
}


@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
    if (resultCode == RESULT_OK) {
        if (requestCode == IDF_ACTIVITY_AUDIO) {
            final String folder = Environment.getExternalStorageDirectory() + "/myAudio/";

            String pathAudio = data.getData().getPath();
            Uri audioUri = data.getData();

            // pathAudio ==  /external/audio/media/8
            // audioUri /external/audio/media/8

            File audio = new File(folder + "audioTest");


            //how to getAudio from data and save in audio file???
        }
    }
}

这两种方法显示了我的问题。使用 Native Recorder Activity 返回的 Uri 对象,我需要将音频保存在自己的文件中。

有人知道怎么做吗?

您能否指出一些链接以全面了解 Uri 的工作原理?

编辑:

字符串“/external/audio/media/8”不代表有效路径。这个字符串是什么意思?

【问题讨论】:

    标签: android android-activity


    【解决方案1】:

    看看Start audio recording with intent of MediaStore.Audio.Media.RECORD_SOUND_ACTIONUsing Intent to record audio

    这两个教程在录制音频后都会为您提供一个 URI,现在使用该 uRI 您可以获得该文件的绝对路径,您还可以使用简单的文件 I/O 操作将该文件写入您想要的位置。

    编辑:

    new File(new URI(androidURI.toString()));
    

    【讨论】:

    • 这两个链接做相同的 I.“使用该 uRI 您可以获得该文件的绝对路径”。这是我的问题!
    • 你检查了路径,是否存在文件?
    【解决方案2】:

    您好,我也在寻找将录制的文件存储在我自己的文件夹中

    但是您可以使用

    获得确切的文件名
    String absolutepath=getRealPathFromURI(audioUri);
    
    
    public String getRealPathFromURI(Uri contentUri) 
    
    {
    
            String[] proj = { MediaStore.Audio.Media.DATA};
            Cursor cursor = managedQuery(contentUri, proj, null, null, null);
            int column_index = `enter code here`cursor.getColumnIndexOrThrow(MediaStore.Audio.Media.DATA);
            cursor.moveToFirst();
            System.out.println("absolutepath audiopath in getRealPathFromURI : "+cursor.getString(column_index));
            return cursor.getString(column_index);
    }
    

    【讨论】:

    • 如果您知道如何将录制的文件存储在单独的文件夹中,可以分享代码吗?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-07-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多