【发布时间】:2016-12-20 20:12:58
【问题描述】:
我正在尝试编写一个简单的小东西,当用户通过与电话交谈“打断”它时,它会停止播放音频文件。我正在使用SoundMeter class that this person wrote 来获取麦克风的最大振幅。我已将阈值设置为800,并希望不断测试麦克风振幅的返回值(每 50 毫秒)。
由于某种原因,当我让“中断”出现并且音频停止时,它会被击中或错过。我希望中断显示幅度高于 800 的整个时间。
handler = new Handler();
final Runnable r = new Runnable() {
@Override
public void run() {
mic_amplitude.setText(""+mSoundMeter.getAmplitude());
if(mSoundMeter.getAmplitude() > threshold) {
Log.d("INTERRUPT", "INTERRUPT");
interrupt.setText("Interrupt");
mBackgroundAudio.pause(mp);
audioButton.setText("Resume Audio");
} else {
interrupt.setText("");
}
handler.postDelayed(this, 50);
}
};
handler.postDelayed(r, 50);
在查看此内容时,我可以看到稳定的 40-50 的幅度,而没有背景噪音,并且在安静地说话时达到 1200-1500 的峰值。我希望在 800 以上的任何时间都显示中断,但目前只是间歇性地显示。
【问题讨论】:
-
我觉得50太小了但我不知道