Localize some strings, clean up the code

pull/14/head
Sam Bosley 13 years ago
parent 35dceb84b3
commit 565894f661

@ -8,12 +8,19 @@ import android.media.AudioFormat;
import android.media.AudioRecord; import android.media.AudioRecord;
import android.media.MediaRecorder.AudioSource; import android.media.MediaRecorder.AudioSource;
/**
* This class combines an Android AudioRecord and our own AACEncoder
* to directly record an AAC audio file from the mic. Users should call
* startRecording() and stopRecording() in sequence, and then listen
* for the encodingFinished() callback to perform final actions like
* converting to M4A format.
* @author Sam
*
*/
public class AACRecorder { public class AACRecorder {
private AudioRecord audioRecord; private AudioRecord audioRecord;
private AACEncoder encoder; private AACEncoder encoder;
private Context context;
private String tempFile;
private boolean recording; private boolean recording;
private AACRecorderCallbacks listener; private AACRecorderCallbacks listener;
@ -34,7 +41,6 @@ public class AACRecorder {
int bytesRead = 0; int bytesRead = 0;
while(recording) { while(recording) {
bytesRead = audioRecord.read(readBuffer, 0, readBuffer.length); bytesRead = audioRecord.read(readBuffer, 0, readBuffer.length);
System.err.println("Bytes read: " + bytesRead);
try { try {
baos.write(readBuffer); baos.write(readBuffer);
} catch (IOException e) { } catch (IOException e) {
@ -50,7 +56,7 @@ public class AACRecorder {
}; };
public AACRecorder(Context context) { public AACRecorder() {
encoder = new AACEncoder(); encoder = new AACEncoder();
} }
@ -58,7 +64,6 @@ public class AACRecorder {
if (recording) if (recording)
return; return;
this.tempFile = tempFile;
audioRecord = new AudioRecord(AudioSource.MIC, SAMPLE_RATE, AudioFormat.CHANNEL_CONFIGURATION_MONO, audioRecord = new AudioRecord(AudioSource.MIC, SAMPLE_RATE, AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, MIN_BUFFER_SIZE); AudioFormat.ENCODING_PCM_16BIT, MIN_BUFFER_SIZE);
@ -83,7 +88,6 @@ public class AACRecorder {
public synchronized void finishRecording() { public synchronized void finishRecording() {
recording = false; recording = false;
audioRecord.release(); audioRecord.release();
System.err.println("Uninit");
encoder.uninit(); encoder.uninit();
if (listener != null) if (listener != null)
listener.encodingFinished(); listener.encodingFinished();
@ -93,17 +97,4 @@ public class AACRecorder {
this.listener = listener; this.listener = listener;
} }
public synchronized boolean convert(String outFile) {
if (recording || tempFile == null)
return false;
try {
new AACToM4A().convert(context, tempFile, outFile);
tempFile = null;
return true;
} catch (IOException e) {
return false;
}
}
} }

@ -42,7 +42,7 @@ public class AACRecordingActivity extends Activity implements AACRecorderCallbac
tempFile = getIntent().getStringExtra(EXTRA_TEMP_FILE); tempFile = getIntent().getStringExtra(EXTRA_TEMP_FILE);
taskId = getIntent().getLongExtra(EXTRA_TASK_ID, 0L); taskId = getIntent().getLongExtra(EXTRA_TASK_ID, 0L);
recorder = new AACRecorder(this); recorder = new AACRecorder();
recorder.setListener(this); recorder.setListener(this);
recorder.startRecording(tempFile); recorder.startRecording(tempFile);
} }
@ -71,15 +71,15 @@ public class AACRecordingActivity extends Activity implements AACRecorderCallbac
speechBubble.setText(R.string.audio_speak_now); speechBubble.setText(R.string.audio_speak_now);
} }
@SuppressWarnings("nls")
private void stopRecording() { private void stopRecording() {
recorder.stopRecording(); recorder.stopRecording();
pd = DialogUtilities.progressDialog(this, "Encoding..."); pd = DialogUtilities.progressDialog(this, getString(R.string.audio_err_encoding));
pd.show(); pd.show();
} }
@SuppressWarnings("nls") @SuppressWarnings("nls")
@Override
public void encodingFinished() { public void encodingFinished() {
try { try {
StringBuilder filePathBuilder = new StringBuilder(); StringBuilder filePathBuilder = new StringBuilder();
@ -99,7 +99,7 @@ public class AACRecordingActivity extends Activity implements AACRecorderCallbac
finish(); finish();
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();
Toast.makeText(this, "Error :(", Toast.LENGTH_LONG); Toast.makeText(this, R.string.audio_err_encoding, Toast.LENGTH_LONG);
} }
pd.dismiss(); pd.dismiss();
} }

@ -12,4 +12,6 @@
<string name="audio_recording_title">Recording Audio</string> <string name="audio_recording_title">Recording Audio</string>
<string name="audio_stop_recording">Stop Recording</string> <string name="audio_stop_recording">Stop Recording</string>
<string name="audio_speak_now">Speak Now!</string> <string name="audio_speak_now">Speak Now!</string>
<string name="audio_encoding">Encoding...</string>
<string name="audio_err_encoding">Error encoding audio</string>
</resources> </resources>

Loading…
Cancel
Save