在Android中,MediaPlayer
一会儿无法使用。代码如下:
播放音乐:
sayib1 = (ImageButton)findViewById(R.id.sayib1);
sayib2 = (ImageButton)findViewById(R.id.sayib2);
sayib3 = (ImageButton)findViewById(R.id.sayib3);
sayib4 = (ImageButton)findViewById(R.id.sayib4);
sayib5 = (ImageButton)findViewById(R.id.sayib5);
sayib6 = (ImageButton)findViewById(R.id.sayib6);
sayib7 = (ImageButton)findViewById(R.id.sayib7);
sayib8 = (ImageButton)findViewById(R.id.sayib8);
sayib9 = (ImageButton)findViewById(R.id.sayib9);
mpsayi = new MediaPlayer();
final String sourcestr = "android.resource://" + this.getPackageName();
sayib1.setOnClickListener(new View.OnClickListener () {
public void onClick (View sayiv1){
mpsayi.reset();
mpsayi.seekTo(0);
sayilayoutt1.setVisibility(View.INVISIBLE);
sayilayoutt2.setVisibility(View.INVISIBLE);
sayibutonlar.setVisibility(View.INVISIBLE);
sayiimagev.setImageResource(R.drawable.sayi1);
sayiimagev.setVisibility(View.VISIBLE);
new Handler().postDelayed( new Runnable() {
public void run(){
sayilayoutt1.setVisibility(View.VISIBLE);
sayilayoutt2.setVisibility(View.VISIBLE);
sayibutonlar.setVisibility(View.VISIBLE);
sayiimagev.setVisibility(View.INVISIBLE);
}
}, 1500);
mpsayi = MediaPlayer.create(getApplicationContext(), R.raw.bir);
mpsayi.start();
}
});
sayib2.setOnClickListener(new View.OnClickListener () {
public void onClick (View sayiv2){
mpsayi.reset();
mpsayi.seekTo(0);
sayilayoutt1.setVisibility(View.INVISIBLE);
sayilayoutt2.setVisibility(View.INVISIBLE);
sayibutonlar.setVisibility(View.INVISIBLE);
sayiimagev.setImageResource(R.drawable.sayi2);
sayiimagev.setVisibility(View.VISIBLE);
new Handler().postDelayed( new Runnable() {
public void run(){
sayilayoutt1.setVisibility(View.VISIBLE);
sayilayoutt2.setVisibility(View.VISIBLE);
sayibutonlar.setVisibility(View.VISIBLE);
sayiimagev.setVisibility(View.INVISIBLE);
}
}, 1500);
mpsayi = MediaPlayer.create(getApplicationContext(), R.raw.iki);
mpsayi.start();
}
});
当我单击ImageButton
时,将播放音乐。
如何解决此问题?希望你能理解。