WEB开发网
开发学院手机开发Android 开发 深入探讨 Android 传感器 阅读

深入探讨 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);

上一页  2 3 4 5 6 7 8 9  下一页

Tags:深入 探讨 Android

编辑录入:coldstar [复制链接] [打 印]
赞助商链接