I am working on a very simple recorder app:
I want to record a person's voice for a few seconds. Then I want to
be able to play it back. Then I want to FTP it to an FTP server.
Should be relatively simple - but I can't get the first portion of
this done. As soon as I set the Audio Source I get a crash in both
the simulator (expected since MediaRecorder is not supported) and on
my phone (not expected unless I am doing something stupidly wrong). I
feel like I am importing the world here trying to find something that
works - and I have gone through like 4 sets of example code (merging
most of it).
Here is what I think is the most simple version of my code that
compiles and runs it just crashes on me when I click the button::::
package com.example.helloandroid;
import java.io.File;
import java.io.IOException;
import java.lang.Object;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.EditText;
import android.widget.Toast;
import android.media.*;
import android.os.Environment;
import android.media.MediaRecorder;
import android.content.*;
import android.provider.*;
import android.net.*;
public class HelloAndroid extends Activity {
MediaRecorder recorder = new MediaRecorder();
String path = "/mnt/sdcard/filename.3gp";
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
final Button button = (Button) findViewById(R.id.button);
button.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
String state =
android.os.Environment.getExternalStorageState();
if
(!state.equals(android.os.Environment.MEDIA_MOUNTED)) {
new IOException("Path to the file could
not be created.");
}
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
//
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
//recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
//recorder.setOutputFile(path);
//recorder.prepare();
//recorder.start();
Toast.makeText(HelloAndroid.this, path,
Toast.LENGTH_SHORT).show();
//recorder.stop();
}
});
}
}
Any help here would be greatly appreciated!
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en