android 录制视频 音频文件夹里,android-如何以编程方式将录制的音频文件保存在另一个文件夹中?...

我正在尝试将录制的音频文件保存在我希望它成为默认文件夹的文件夹中.但是我不知何故没有这样做.

我的代码:

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

它确实调用了录音机应用.而且当我按下停止按钮时,它返回到我的应用程序,并有一个祝酒词说它已保存.但是,而不是保存在“记录”文件夹中,而是保存在默认文件夹中.

我意识到logcat中有错误msg:

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

我不确定在调用相机应用程序时代码出了什么问题.

解决方法:

通过这种方式,用MediaRecorder录制:

要开始录制:

public void startRecording()

{

MediaRecorder recorder = new MediaRecorder();

recorder.setAudioSource(MediaRecorder.AudioSource.MIC);

recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);

recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);

recorder.setOutputFile(getFilename());

recorder.setOnErrorListener(errorListener);

recorder.setOnInfoListener(infoListener);

try

{

recorder.prepare();

recorder.start();

}

catch (IllegalStateException e)

{

e.printStackTrace();

} catch (IOException e)

{

e.printStackTrace();

}

}

停止:

private void stopRecording()

{

if(null != recorder)

{

recorder.stop();

recorder.reset();

recorder.release();

recorder = null;

}

对于选定的文件夹:

private String getFilename()

{

String filepath = Environment.getExternalStorageDirectory().getPath();

File file = new File(filepath,AUDIO_RECORDER_FOLDER);

if(!file.exists()){

file.mkdirs();

}

return (file.getAbsolutePath() + "/" + System.currentTimeMillis() + ".mp3");

}

标签:android,audio-recording,voice-recording

来源: https://codeday.me/bug/20191011/1889549.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值