活动whith音高检测TarsosDSP无重启

时间:2017-01-30 13:18:23

标签: java android tarsosdsp

我在音乐应用程序中写了一个吉他调音器。主要活动在点击按钮时启动调谐器。调谐器工作正常。但如果我回到主要活动。 调谐器活动开始,但音调检测没有。 线程不会停止录像机。

我使用

从主要活动中启动活动Act_Accordage
public void clicAccordage(View v){
        Intent intentAct_Accordage = new Intent(this, Act_Accordeur .class);
    startActivity(intentAct_Accordage);
}

这是我的Act_Accordage活动

public final AudioDispatcher dispatcher = AudioDispatcherFactory.fromDefaultMicrophone(22050, 2048, 0);
    ....
          dispatcher.addAudioProcessor(new PitchProcessor(PitchEstimationAlgorithm.YIN, 22050, 2048, new PitchDetectionHandler() {

                @Override
                public void handlePitch(PitchDetectionResult pitchDetectionResult,
                                        AudioEvent audioEvent) {
                    final float pitchInHz = pitchDetectionResult.getPitch();
                    if (Logo.interrupted()) {
                        return;
                    }
                    if (pitchInHz > -1) {
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                // display name note and cursor ou UI thread
                               textFreqNote.setText(String.valueOf(pitchInHz) + " CREATE "); 
                               Affcurseur(pitchInHz);
                             });
                    }

                }
            }));
             new Thread(dispatcher, "Audio Dispatcher");

    2***/I come back main with  button or backbutton
    public void onclicSetBackMain(View v) {
            Act_Accordeur.this.finish();
            Toast.makeText(Act_Accordeur.this, "Guitare accordée", Toast.LENGTH_LONG).show();}

1 个答案:

答案 0 :(得分:0)

使用dispatcher.stop();停止Audio Dispatcher线程。我花了很长时间在官方文档中,但这是值得的。