如果幅度大于给定的阈值,我想重复录制声音并在500ms后检查振幅,然后我想再进行一次活动。
但是当我尝试这样做时,我的活动会不断地像往复一样切换
public class MediaSound extends Activity
{
MediaRecorder recorder;
String mFileName;
Handler mHandler;
boolean isRecording = false;
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
mHandler = new Handler();
}
private Runnable runnable = new Runnable()
{
@Override
public void run()
{
// TODO Auto-generated method stub
if( recorder != null)
{
int amplitude =recorder.getMaxAmplitude();
//Log.d("AMPLITUDE----->", " "+amplitude);
if(amplitude>10000)
{
next();
}
}
}
mHandler.postDelayed(runnable, 500);
}
};
@Override
protected void onStart()
{
super.onStart();
recorder = new MediaRecorder();
recorder.setAudioSource(MediaRecorder.AudioSource.MIC);
recorder.setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
recorder.setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
Log.d("MediaSound", "I am in MediaSound");
mFileName = Environment.getExternalStorageDirectory().getAbsolutePath();
mFileName += "/audiorecordtest.3gp";
recorder.setOutputFile(mFileName);
try
{
recorder.prepare();
}
catch (IllegalStateException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
recorder.start();
mHandler.postDelayed(runnable, 500);
if(isRecording)
{
}
}
public void next()
{
mHandler.removeCallbacks(runnable);
Log.d("In the next", "Kya karu");
recorder.stop();
recorder.release();
this.finish();
Intent newIntent = new Intent(getApplicationContext(), NewMedia.class);
startActivity(newIntent);
}