开发者

Play a sound when the progressbar reaches the end, not working!

开发者 https://www.devze.com 2023-03-13 23:40 出处:网络
public class MyCount extends CountDownTimer { MediaPlayer mp = MediaPlayer.create(this, R.raw.beep1); public MyCount(long millisInFuture, long countDownInterval)

public class MyCount extends CountDownTimer {

    MediaPlayer mp = MediaPlayer.create(this, R.raw.beep1);

    public MyCount(long millisInFuture, long countDownInterval) 
    {
        super(millisInFuture, countDownInterval);
    }
    @Override
    public void onFinish() 
    {
        mp.star开发者_StackOverflowt();
        //Start.this.finish();
    }
    @Override
    public void onTick(long millisUntilFinished) 
    {
        total++;
        progre.setProgress(total);
    }   
}

I want topaly a sound when the progress bar reaches the end (after 30sec) but it's not playing.

Can anybody help me??


I think you need to use the following line:

MediaPlayer mp = MediaPlayer.create(ActivityName.this, R.raw.beep1);

the 'this' in your code is referring to the MyCount class buut you want to use the Activity.


Hmmmmm. It should work because you are playing from a raw resource...maybe the mediaplayer is already being used by something else. Try putting mp.reset() then mp.prepare() before mp.start().

Let me know if that works...

Also JDx answer above may do the trick.

0

精彩评论

暂无评论...
验证码 换一张
取 消