As i have re-written this several times now. It is very nasty. Im testing on a DroidX where everything i use to record a call is coming back empty. Anyone know why or a fix?
My recording class: [code] package com.call.tests; import android.media.AudioFormat; import android.media.AudioRecord; import android.media.MediaRecorder; import android.media.MediaRecorder.AudioSource; import android.os.Environment; import android.util.Log; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; import java.io.IOException; import java.text.SimpleDateFormat; import java.util.Date; class Record { private MediaRecorder recorder = null; private AudioRecord rawRecorder = null; public boolean recording = false; private Thread recordingThread = null; public String path = ""; public String tempPath = ""; public void BeginRecording(String incomingNumber) { try { //recorder = new MediaRecorder(); if(incomingNumber.length() == 0) incomingNumber = "noNumber"; Date dateNow = new Date (); SimpleDateFormat dateformat = new SimpleDateFormat("_kms_yyyyMMdd"); StringBuilder now = new StringBuilder( dateformat.format( dateNow ) ); path = incomingNumber + now.toString(); Log.d("TEST", "NEW PATH: " + path); String longPath = sanitizePath(path, false); File directory = new File(longPath).getParentFile(); if (!directory.exists() && !directory.mkdirs()) { Log.d("TEST", "Path to file could not be created."); } else { Log.d("TEST", "Path exists."); } rawRecorder = findAudioRecord(); rawRecorder.startRecording(); recording = true; recordingThread = new Thread(new Runnable() { @Override public void run() { writeAudioDataToFile(); } },"AudioRecorder Thread"); recordingThread.start(); /*recorder.reset(); recorder.setAudioSource(MediaRecorder.AudioSource.VOICE_DOWNLINK); recorder.setOutputFormat(MediaRecorder.OutputFormat.DEFAULT); recorder.setOutputFile(longPath); recorder.setAudioEncoder(MediaRecorder.AudioEncoder.DEFAULT); Log.e("TEST", "Recording values set"); //try{ recorder.prepare(); recorder.start(); //Log.e("TEST", "Recording: " + recording); //} catch (IOException e) { //Log.e("TEST", "prepare() failed : " + e.toString()); //}*/ } catch(Exception ex) { Log.d("TEST", "BeginRecording: " + ex.toString()); } } private static int[] mSampleRates = new int[] { 8000, 11025, 22050, 44100 }; public AudioRecord findAudioRecord() { for (int rate : mSampleRates) { for (short audioFormat : new short[] { AudioFormat.ENCODING_PCM_8BIT, AudioFormat.ENCODING_PCM_16BIT }) { for (short channelConfig : new short[] { AudioFormat.CHANNEL_IN_MONO, AudioFormat.CHANNEL_IN_STEREO }) { try { Log.d("TEST", "Attempting rate " + rate + "Hz, bits: " + audioFormat + ", channel: " + channelConfig); int bufferSize = AudioRecord.getMinBufferSize(rate, channelConfig, audioFormat); if (bufferSize != AudioRecord.ERROR_BAD_VALUE) { AudioRecord recorder = new AudioRecord(AudioSource.VOICE_CALL, rate, channelConfig, audioFormat, bufferSize); if (recorder.getState() == AudioRecord.STATE_INITIALIZED) return recorder; } } catch (Exception e) { Log.e("TEST", rate + "Exception, keep trying.",e); } } } } return null; } public void writeAudioDataToFile() { tempPath = "temp_raw_record"; String longPath = sanitizePath(tempPath, true); File directory = new File(longPath).getParentFile(); if (!directory.exists() && !directory.mkdirs()) { Log.d("TEST", "Path to temp file could not be created."); } else { Log.d("TEST", "Temp path exists."); } byte data[] = new byte[AudioRecord.getMinBufferSize(rawRecorder.getSampleRate(),rawRecorder.getChannelCount(),rawRecorder.getAudioFormat())]; String filename = longPath; FileOutputStream os = null; try { os = new FileOutputStream(filename); } catch (FileNotFoundException e) { e.printStackTrace(); } int read = 0; if(null != os){ while(recording){ read = rawRecorder.read(data, 0, AudioRecord.getMinBufferSize(rawRecorder.getSampleRate(),rawRecorder.getChannelCount(),rawRecorder.getAudioFormat())); if(AudioRecord.ERROR_INVALID_OPERATION != read) { try { os.write(data); } catch (IOException e) { e.printStackTrace(); } } } try { os.close(); } catch (IOException e) { e.printStackTrace(); } } } public void EndRecording() { /*try{ recorder.stop(); recorder.release(); } catch(Exception ex) { Log.d("TEST", "EndRecording: " + ex.toString()); }*/ if(recording == true) { rawRecorder.stop(); rawRecorder.release(); } recording = false; Log.d("TEST", "EndRecording finished"); } private String sanitizePath(String path1, boolean raw) { if (!path.startsWith("/")) path1 = "/CT/" + path; if (!path.contains(".")) if(raw == true) path1 += ".raw"; else path1 += ".3gp"; File root = Environment.getExternalStorageDirectory(); Log.d("TEST", "ROOT: " + root); Log.d("TEST", "ROOTPATH: " + root + path1); return root + path1; } }[/code] -- You received this message because you are subscribed to the Google Groups "Android Developers" group. To post to this group, send email to android-developers@googlegroups.com To unsubscribe from this group, send email to android-developers+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en