我试图从它检测到的每次拍手中获取振幅读数,但每次检测到拍手时,我都会不断IllegalStateException
地0
从getMaxAmplitude()
. 我做错什么了吗?有没有解决的办法?请告诉我!
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//Checks Permission
checkPermission(Manifest.permission.RECORD_AUDIO,REQUEST_RECORD_AUDIO_PERMISSION);
double threshold = 8;
double sensitivity = 45;
PercussionOnsetDetector mPercussionDetector = new PercussionOnsetDetector(22050, 1024,
new OnsetHandler() {
@Override
public void handleOnset(double time, double salience) {
/* try {
new MediaRecorder().setAudioSource(MediaRecorder.AudioSource.MIC);
new MediaRecorder().setOutputFormat(MediaRecorder.OutputFormat.THREE_GPP);
new MediaRecorder().setAudioEncoder(MediaRecorder.AudioEncoder.AMR_NB);
new MediaRecorder().setOutputFile("dev/null");
new MediaRecorder().prepare();
new MediaRecorder().start();
} catch (Exception e) {
e.printStackTrace();
} */
runOnUiThread(new Runnable() {
@Override
public void run() {
System.out.println(new MediaRecorder().getMaxAmplitude());
System.out.println("YAAAYYY");
}
});
}
}, sensitivity, threshold);
dispatcher.addAudioProcessor(mPercussionDetector);
new Thread(dispatcher,"Audio Dispatcher").start();
}