Android 我想用mediaplayer录制声音,然后计算;振幅“;用于随着声音的变化上下移动杆
我想用MediaRecorder来记录声音,然后计算随着声音的变化而上下移动条的“振幅”。我还没有找到任何合适的解决方案。有什么建议吗。??编辑:我现在设法把手伸进了它,问题是我尝试使用处理程序GetMaxAmplium()来查找振幅,之后我尝试使用该值来显示杆向上移动,但它不起作用,然后我打印了GetMaxAmplium()的值。当然,该值为零。这里可能有什么问题。??这是一段代码 公开募捐{ 试一试{Android 我想用mediaplayer录制声音,然后计算;振幅“;用于随着声音的变化上下移动杆,android,handler,android-mediarecorder,Android,Handler,Android Mediarecorder,我想用MediaRecorder来记录声音,然后计算随着声音的变化而上下移动条的“振幅”。我还没有找到任何合适的解决方案。有什么建议吗。??编辑:我现在设法把手伸进了它,问题是我尝试使用处理程序GetMaxAmplium()来查找振幅,之后我尝试使用该值来显示杆向上移动,但它不起作用,然后我打印了GetMaxAmplium()的值。当然,该值为零。这里可能有什么问题。??这是一段代码 公开募捐{ 试一试{ mRecorder.start(); wh
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); }
您可以使用计时器在每.5秒后调用getMaxAmplitue()
MyTimer tim = new new MyTimer(30000,500);;
mRecorder.start();
tim.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); }
public class MyTimer extends CountDownTimer {
public MyTimer(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
}
@Override
public void onTick(long millisUntilFinished) {
int amplitude = mRecorder.getMaxAmplitude();
Log.i("AMPLITUDE", new Integer(amplitude).toString());
}
}
您可以在计时器中使用此处理程序在每.5秒后获取结果。您可以在每.5秒后使用计时器调用getMaxAmplitue()
MyTimer tim = new new MyTimer(30000,500);;
mRecorder.start();
tim.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); }
public class MyTimer extends CountDownTimer {
public MyTimer(long millisInFuture, long countDownInterval) {
super(millisInFuture, countDownInterval);
// TODO Auto-generated constructor stub
}
@Override
public void onFinish() {
// TODO Auto-generated method stub
}
@Override
public void onTick(long millisUntilFinished) {
int amplitude = mRecorder.getMaxAmplitude();
Log.i("AMPLITUDE", new Integer(amplitude).toString());
}
}
您可以在计时器中使用此处理程序,每.5秒后获取一次结果。太好了,没有人可以提供帮助。!!!至少让我知道该怎么做。.如果我想调用getMaxAmplitue()在处理程序中每隔.5秒之后,我如何才能连续读取..太好了,没有人可以帮助..!!!至少让我知道该怎么做..如果我想在处理程序中每隔.5秒调用getMaxAmplitue(),我如何才能连续读取。。??