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.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 {
private AudioRecord audioRecord;
private AACEncoder encoder;
private Context context;
private String tempFile;
private boolean recording;
private AACRecorderCallbacks listener;
@ -34,7 +41,6 @@ public class AACRecorder {
int bytesRead = 0;
while(recording) {
bytesRead = audioRecord.read(readBuffer, 0, readBuffer.length);
System.err.println("Bytes read: " + bytesRead);
try {
baos.write(readBuffer);
} catch (IOException e) {
@ -50,7 +56,7 @@ public class AACRecorder {
};
public AACRecorder(Context context) {
public AACRecorder() {
encoder = new AACEncoder();
}
@ -58,7 +64,6 @@ public class AACRecorder {
if (recording)
return;
this.tempFile = tempFile;
audioRecord = new AudioRecord(AudioSource.MIC, SAMPLE_RATE, AudioFormat.CHANNEL_CONFIGURATION_MONO,
AudioFormat.ENCODING_PCM_16BIT, MIN_BUFFER_SIZE);
@ -83,7 +88,6 @@ public class AACRecorder {
public synchronized void finishRecording() {
recording = false;
audioRecord.release();
System.err.println("Uninit");
encoder.uninit();
if (listener != null)
listener.encodingFinished();
@ -93,17 +97,4 @@ public class AACRecorder {
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);
taskId = getIntent().getLongExtra(EXTRA_TASK_ID, 0L);
recorder = new AACRecorder(this);
recorder = new AACRecorder();
recorder.setListener(this);
recorder.startRecording(tempFile);
}
@ -71,15 +71,15 @@ public class AACRecordingActivity extends Activity implements AACRecorderCallbac
speechBubble.setText(R.string.audio_speak_now);
}
@SuppressWarnings("nls")
private void stopRecording() {
recorder.stopRecording();
pd = DialogUtilities.progressDialog(this, "Encoding...");
pd = DialogUtilities.progressDialog(this, getString(R.string.audio_err_encoding));
pd.show();
}
@SuppressWarnings("nls")
@Override
public void encodingFinished() {
try {
StringBuilder filePathBuilder = new StringBuilder();
@ -99,7 +99,7 @@ public class AACRecordingActivity extends Activity implements AACRecorderCallbac
finish();
} catch (IOException e) {
e.printStackTrace();
Toast.makeText(this, "Error :(", Toast.LENGTH_LONG);
Toast.makeText(this, R.string.audio_err_encoding, Toast.LENGTH_LONG);
}
pd.dismiss();
}

@ -12,4 +12,6 @@
<string name="audio_recording_title">Recording Audio</string>
<string name="audio_stop_recording">Stop Recording</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>

Loading…
Cancel
Save