在我的android应用中,我只需要录制音频1分钟?有谁能帮助我录制一定时间的音频?我已经编写了用于录制音频的代码,只有在按下停止按钮时它才会停止,但是我需要在1分钟后自动停止录制...
这是我的代码..但是没有用
try {
recorder.prepare();
recorder.start();
//Declare the timer
Timer t = new Timer();
//Set the schedule function and rate
t.scheduleAtFixedRate(new TimerTask() {
@Override
public void run() {
runOnUiThread(new Runnable() {
@Override
public void run() {
Toast.makeText(AudioRecordingActivity.this, "record successfullly ",
Toast.LENGTH_SHORT).show();
i1=i1+1;
}
});
//Called each time when 1000 milliseconds (1 second) (the period parameter)
}
},
//Set how long before to start calling the TimerTask (in milliseconds)
0,
//Set the amount of time between each execution (in milliseconds)
10*1000);
if (null != recorder) {
recorder.stop();
recorder.reset();
recorder.release();
recorder = null;
Toast.makeText(AudioRecordingActivity.this, "record successfullly",
Toast.LENGTH_SHORT).show();
}
} catch (IllegalStateException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
最佳答案
试试下面的代码
recorder.start();
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
recorder.stop();
}
}, 60000);
关于android - 如何只录制1分钟的音频?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21522574/