Goofy Goofy - 1 year ago 60
Android Question

Playing audio file for specific time

Guys i able to play audio file using Mediaplayer. But i need to play a audio file for specific time.

Eg: play audio1.mp3 till 5 minutes.
The audio file is of 10 seconds only.But it should keep playing till 5 minutes.

Answer Source

try this

 mediaplayerplayer.setLooping(true);<--- this lets the audio to loop...

and this is the countdown timer

MyCount counter;
Long s1;

counter= new MyCount(300000,1000);

public void asdf(View v){  <---- method for onclick of buttons pause and resuming timer
        case<-- for pause
        case<--- for resume
            counter= new MyCount(s1,1000);

public class MyCount extends CountDownTimer {
    public MyCount(long millisInFuture, long countDownInterval) {
        super(millisInFuture, countDownInterval);

    public void onFinish() {

    public void onTick(long millisUntilFinished) {

this helps you to pause the mediaplayer also... along with timer.. and lets you play the song for complete 5 mins

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download