我想使用 MediaRecorder 来录制声音,然后想计算随着声音的变化上下移动 Bars 的“幅度”。我还没有建立任何合适的解决方案。有什么建议么。??已编辑:我现在设法把手伸进去,问题是我已经尝试使用 Handler getMaxAmplitude() 来查找幅度,之后我尝试使用该值来显示条向上移动它不起作用然后我打印了getMaxAmplitude() 的值肯定为零。这里可能有什么问题。??这是一段代码 public void run() { try {
mRecorder.start();
while (this.mIsRunning) {
// creating these variables here so that
// the mode change can be handled
double amp = getAmplitude();
Message msg = mHandle.obtainMessage(MY_MSG, amp);
mHandle.sendMessage(msg);
}
} catch (Exception e) {
e.printStackTrace();
Message msg = mHandle.obtainMessage(ERROR_MSG,
e.getLocalizedMessage() + "");
mHandle.sendMessage(msg);
}
if (mRecorder != null) {
mRecorder.stop();
mRecorder.release();
mRecorder = null;
}
}
public double getAmplitude() {
if (mRecorder != null) {
powerDb = 20 * Math.log10(mRecorder.getMaxAmplitude() / 2700.0);
return (powerDb);
}
else {
return 1;
}
}
public Handler mhandle = new Handler() {
@Override
public void handleMessage(Message msg) {
switch (msg.what) {
case MY_MSG:
// mSplModeTV.setText(" " + msg.obj);
if (audioEngineFlag == 1) {
String s1 = msg.obj.toString();
float f = Float.valueOf(s1.trim()).floatValue();
Log.v(TAG, "amplitude=" + f); }