how to play a sound on click of button

后端 未结 4 1474
梦毁少年i
梦毁少年i 2021-01-15 13:16

i am trying to play sound file on the emulator on click of button but i am getting message \"application play audio has stopped unexpectedly\"

my codes are:

4条回答
  •  半阙折子戏
    2021-01-15 14:15

    mp.start() should be before starting a new activity.

          btnSound.setOnClickListener(new View.OnClickListener() {
    
                @Override
                public void onClick(View v) {
                mp.start();
                startActivity(new Intent(currentActivityName.this, newActivityName.class)); 
    
                }
            }); 
    

提交回复
热议问题