本文介绍了如何保存在另一个文件夹中录制的音频文件编程?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图挽救,我希望它是而不是默认的文件夹中的文件夹中录制的音频文件。但不知怎的,我没有这样做。

i'm trying to save the recorded audio files in a folder that i wanted it to be rather then the default folder. but somehow i failed to do so.

我的code:

Intent recordIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
Uri mUri = Uri.fromFile(new File(Environment.getExternalStorageDirectory(), "/Record/sound_"+ String.valueOf(System.currentTimeMillis()) + ".amr"));
recordIntent.putExtra(android.provider.MediaStore.EXTRA_OUTPUT, mUri);
startActivityForResult(recordIntent, RESULT_OK);

它确实调用录音笔的应用程序。而且当我preSS停止按钮,就回到我的应用程序,并拥有举杯出现称其保存。但是,而不是节约在我的录音文件夹,将其保存在默认的文件夹。

it did calls the voice recorder app. and also when i press the stop button, it return to my app and have a toast appeared saying its saved. but, rather then saving in my Record folder, it save in the default folder.

我意识到,在logcat中的错误信息:

i realized that there is error msg in the logcat :

01-29 01:34:23.900: E/ActivityThread(10824): Activity com.sec.android.app.voicerecorder.VoiceRecorderMainActivity has leaked ServiceConnection com.sec.android.app.voicerecorder.util.VRUtil$ServiceBinder@405ce7c8 that was originally bound here

我不知道问题出在哪里为code工作时,我调用摄像头应用程序。

i'm not sure what went wrong as the code works when i call the camera app.

推荐答案

我已经找到一种方法来解决这个问题,尽管它需要一个圆形去做而不是让的地步直,但其最好的,我已经得到了它也工作。

i've found a way to solve this problem, even though it takes a round to do it rather then getting to the point straight, but its the best that i've got and it also work.

而不是调用额外的语音记录器的应用程序包括,我只是把它在没有任何输入:

instead of calling the voice recorder app with extra included, i just call it without any input :

Intent recordIntent = new Intent(MediaStore.Audio.Media.RECORD_SOUND_ACTION);
startActivityForResult(recordIntent, 1111);

然后,添加一个onActivityResult,与请求code = = 1111(取决于你放)和检索的最后一个修改后的文件,它由从记录仪声音的默认文件夹的扩展名3GA的

then, add an onActivityResult, with the request code == 1111 (depends on what you put) and retrieve the last modified file that consist of the extension "3ga" from the default folder of recorder "Sounds"

@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data)
{
    super.onActivityResult(requestCode, resultCode, data);

    if(requestCode == 1111)
    {
         File folder = new File(Environment.getExternalStorageDirectory(), "/Sounds");
         long folderModi = folder.lastModified();

    FilenameFilter filter = new FilenameFilter()
    {
        public boolean accept(File dir, String name)
        {
            return (name.endsWith(3ga));
        }
    };

    File[] folderList = folder.listFiles(filter);

    String recentName = "";

    for(int i=0; i<folderList.length;i++)
    {
        long fileModi = folderList[i].lastModified();

        if(folderModi == fileModi)
        {
            recentName = folderList[i].getName();
        }
    }
}

这样一来,我可以得到该文件的名称也做了修改(例如,重命名)吧。

this way, i can get the name of the file and also do the modification (e.g renaming) with it.

希望这可以帮助其他人。 =)

hope this helps other people. =)

这篇关于如何保存在另一个文件夹中录制的音频文件编程?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 07:43