如果学过就知道这是一个相对简单的问题,
首先进行布局,就是设置写按钮,文字之类的。
2.写个activity,调用系统录音程序
public class SoundRecorderActivity extends Activity implements OnClickListener {
private Button btnStart
private Button btnStop
private Button btnPlay
private MediaRecorder mMediaRecorder
private File recAudioFile
private MusicPlayer mPlayer
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState)
setContentView(R.layout.main)
坦液 setupViews()
}
private void setupViews() {
btnStart = (Button) findViewById(R.id.start)
btnStop = (Button) findViewById(R.id.stop)
btnPlay = (Button) findViewById(R.id.play)
btnStart.setOnClickListener(this)
btnStop.setOnClickListener(this)
btnPlay.setOnClickListener(this)
recAudioFile = new File("/mnt/sdcard", "new.amr")
}
埋启 @Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.start:
startRecorder()
break
case R.id.stop:
stopRecorder()
break
case R.id.play:
mPlayer = new MusicPlayer(SoundRecorderActivity.this)
mPlayer.playMicFile(recAudioFile)
break
default:
break
}
}
private void startRecorder() {
mMediaRecorder = new MediaRecorder()
if (recAudioFile.exists()) {
recAudioFile.delete()
}
mMediaRecorder.setAudioSource(MediaRecorder.AudioSource.MIC)
mMediaRecorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT)
mMediaRecorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT)
mMediaRecorder.setOutputFile(recAudioFile.getAbsolutePath())
try {
mMediaRecorder.prepare()
} catch (IllegalStateException e) {
e.printStackTrace()
} catch (IOException e) {
e.printStackTrace()
}
弯信如
mMediaRecorder.start()
}
private void stopRecorder(){
if (recAudioFile!=null) {
mMediaRecorder.stop()
mMediaRecorder.release()
}
}
}</span>
如何保存到特定的目录,只需要得到recAudioFile = new File("/mnt/sdcard", "new.amr") 就可以了。
3.设置播放类,也是调用播放方法。MediaPlayer
4添加权限
如果是要把电脑上的渗败文件放到模拟器上,用adb push ,eclipse ADT 插件的file Explorer 上有图形的按钮很容易 *** 作,如果是要在代码中复制宽凳文件 的话,看看api demo 吧,有很详细的例子丛巧颤。欢迎分享,转载请注明来源:内存溢出
评论列表(0条)