作者rbsmile (卷卷*)
看板AndroidDev
标题[问题] 录音程式 setAudioSourceFail
时间Sun Dec 9 15:07:34 2012
作者 rbsmile (卷卷*) 看板 Android
标题 [请益] 录音程式
时间 Sun Dec 9 14:55:36 2012
───────────────────────────────────────
最近教授给了我个题目
殊不知才写第一题就卡到阴
是要写一个录音跟录影的app
储存权限设了
画面可以跑出来 但是一按下按钮可怕的事情就发生了
log cat : RunTimeException setAudioSourceFaild
以下是程式码
package test.example.videorecorderactivity;
import java.io.File;
import java.io.IOException;
import android.app.Activity;
import android.media.MediaRecorder;
import android.os.Bundle;
import android.os.Environment;
import android.view.View;
import android.widget.Button;
public class VideoRecorderActivity extends Activity {
private Button StartMediaRecord;
private Button StartSoundRecord;
private Button StopMediaRecord;
private Button StopSoundRecord;
private Button Exit;
private MediaRecorder mediaRecorder;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_recorder);
StartMediaRecord = (Button)findViewById(R.id.StartMediaRecord);
StartSoundRecord = (Button)findViewById(R.id.StartSounadRecord);
StopMediaRecord = (Button)findViewById(R.id.StopMediaRecord);
StopSoundRecord = (Button)findViewById(R.id.StopSoundRecord);
Exit = (Button)findViewById(R.id.Exit);
StartSoundRecord.setEnabled(true );
StopSoundRecord.setEnabled(false);
StartMediaRecord.setEnabled(true );
StopMediaRecord.setEnabled(false );
Exit.setEnabled(true );
mediaRecorder = null;
StartSoundRecord.setOnClickListener(new Button.OnClickListener(){
@Override
public void onClick(View v) {
String SoundRecordfileName = "SoundRecord.amr";
try {
//取得SD卡位置
File SDCardpath = Environment.getExternalStorageDirectory();
//SD卡位置下的/download目录
File myDataPath = new File( SDCardpath.getAbsolutePath() + "/download" );
//判断若资料夹不存在则新建download资料夹
if( !myDataPath.exists() ) myDataPath.mkdirs();
mediaRecorder = new MediaRecorder();
//设定音源为麦克风
mediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC);
//设定输出档案格式为THREE_GPPRAW_AMR:3pg格式,H263视频/ARM音频编码
//RAW_AMR:只支持音频且音频编码要求维AMR_NB
mediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.RAW_AMR);
//设定音频文件的编码
mediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
//设定输出文件的路径
File recodeFile = new File(SDCardpath.getAbsolutePath() +
"/download/"+SoundRecordfileName);
mediaRecorder.setOutputFile(recodeFile.getAbsolutePath());
mediaRecorder.prepare();
mediaRecorder.start();
}
catch (IOException e) {e.printStackTrace();}
}});
}
}
恳请各位大大救命
程式码几乎都是上网找资料打的
因为其实只有去补习班上过几堂课翻翻书学过而已
学校并没有开android的课程
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 1.160.218.201
※ 编辑: rbsmile 来自: 1.160.218.201 (12/09 15:08)
1F:推 showsky:android.permission.RECORD_AUDIO 12/09 15:17
2F:→ rbsmile:感谢 我怎麽这麽笨a没想到record也要权限= ='' 12/09 15:42