Call method after 5 millisecond
You can use the method postDelayed. In the example below I run my routine 100 millis after to call the method.
new Handler().postDelayed(new Runnable() {
@Override
public void run() {
barVolume.setProgress(audioManager.getStreamVolume(AudioManager.STREAM_MUSIC));
}
},
100);
try this:
//Auto Start after 2 seconds
if(ENABLE_AUTO_START) {
new Timer().schedule(new TimerTask() {
@Override
public void run() {
// this code will be executed after 2 seconds
doThis();
}
}, 2000);
}
5 milliseconds is a very short time period and you can't limit audio output to such duration.
you can use Handler
to execute a delayed function but it will not ensure execution at 5 milliseconds after scheduling.
a code for doing that:
Handler handler = new Handler();
handler.postDelayed(new Runnable(){
@Override
public void run(){
startRecord();
mp.stop();
mp.release();
}
}, 5);