How to call record method after 5 millisecond playing audio with MediaPlayer. I tried something like that but i don't know and i didn't find any good examples to end this.
while(mp.isPlaying()){
if(record=0){
for(int i=0; i<5millisec; i++){ //how to define 5 millisec or is any better solution
}
startRecord();
record=1;
}
}
mp.stop();
mp.release();
mp=null;
This example demonstrates how do I call method after a delay in android. Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project. Step 2 − Add the following code to res/layout/activity_main. xml.
The setInterval() method calls a function at specified intervals (in milliseconds). The setInterval() method continues calling the function until clearInterval() is called, or the window is closed. 1 second = 1000 milliseconds.
To call a method in Java, you type the method's name, followed by brackets. This code simply prints “Hello world!” to the screen. Therefore, any time we write helloMethod(); in our code, it will show that message to the screen.
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);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With