深入探讨 Android 传感器
2010-07-21 01:10:00 来源:WEB开发网核心提示:null; private static final String TAG="SoundRecordingDemo"; protected void startRecording() throws IOException { mrec.setAudioSource(MediaRecorder.Aud
null; private static final String TAG="SoundRecordingDemo"; protected void
startRecording() throws IOException {
mrec.setAudioSource(MediaRecorder.AudioSource.MIC);
mrec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mrec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB); if (mSampleFile ==
null) { File sampleDir = Environment.getExternalStorageDirectory(); try {
audiofile = File.createTempFile("ibm", ".3gp", sampleDir); } catch (IOException
e) { Log.e(TAG,"sdcard access error"); return; } }
mrec.setOutputFile(audiofile.getAbsolutePath()); mrec.prepare(); mrec.start(); }
protected void stopRecording() { mrec.stop(); mrec.release();
processaudiofile(audiofile.getAbsolutePath()); } protected void
processaudiofile() { ContentValues values = new ContentValues(3); long current =
System.currentTimeMillis(); values.put(MediaStore.Audio.Media.TITLE, "audio" +
audiofile.getName()); values.put(MediaStore.Audio.Media.DATE_ADDED, (int)
(current / 1000)); values.put(MediaStore.Audio.Media.MIME_TYPE, "audio/3gpp");
values.put(MediaStore.Audio.Media.DATA, audiofile.getAbsolutePath());
ContentResolver contentResolver = getContentResolver(); Uri base =
MediaStore.Audio.Media.EXTERNAL_CONTENT_URI; Uri newUri =
contentResolver.insert(base, values); sendBroadcast(new
Intent(Intent.ACTION_MEDIA_SCANNER_SCAN_FILE, newUri)); } MediaRecorder mrec
;
File audiofile = null;
private static final String TAG="SoundRecordingDemo";
protected void startRecording() throws IOException
{
mrec.setAudioSource(MediaRecorder.AudioSource.MIC);
mrec.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
mrec.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
if (mSampleFile == null)
{
File sampleDir = Environment.getExternalStorageDirectory();
try
{
audiofile = File.createTempFile("ibm", ".3gp", sampleDir);
更多精彩
赞助商链接