开发者

Playing sound on EVERY buttonclick(Android=

I am currently working on an application for Android and I'm using Eclipse and of course Android SDK, but I have bumped in to a problem that is almost the only thing I need to fix before I can relaese a beta-version to Android Market.

So, my problem is that I have an xml with 4 different buttons, and if the user press on a certain开发者_StackOverflow中文版 button, one sound will be played, and if the user press any of the other buttons is pressed another sound will play but the sound only play sometimes, I want it to play every time the user press a button. Here's my code(concerning the mediaplayer):

    public MediaPlayer right=null;  
    public MediaPlayer wrong=null; 

    if(right!=null) {  
         right.reset();  
      right.release();  
    }  
    if(wrong!=null) {  
         wrong.reset();  
            wrong.release();  
    }  
    right = MediaPlayer.create(getBaseContext(), R.raw.rightsound);
    wrong = MediaPlayer.create(getBaseContext(), R.raw.wrongsound);
    if(****()){
        right.start();
    } 
    else {
     wrong.start();
 } 

That's my code and I would be very grateful if somebody could help me solve my problem.


new Thread() {
    public void run() {
        int sound = R.raw.wrongsound;
        if(****()) {
            sound = R.raw.rightsound;
        }
        mp = MediaPlayer.create(Test.this, sound);   
        mp.setOnCompletionListener(new OnCompletionListener() {
            @Override
            public void onCompletion(MediaPlayer mp) {
                mp.release();
            }
        });
        mp.start();
    }
}.start();
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜