دستوری شرطی رو اینطور نوشتم ولی موقع اجرا خطا می ده.لطفا اگه امکانش هست دستور شرطی رو برام بنویسید
اینم کد:
اینم کد:
کد پیاچپی:
final Button bu1=(Button)findViewById(R.id.no1);
final Button bu2=(Button)findViewById(R.id.no2);
bu1.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View p1, MotionEvent p2){
switch(p2.getActionMasked()){
case MotionEvent.ACTION_DOWN:
if(stop()){
mp11=MediaPlayer.create(MainActivity.this,R.raw.sol1);
mp11.start();
mp11.setLooping(true);
mp11.setVolume(100,100);
}
else{
mp11.stop();
}
break;
case MotionEvent.ACTION_UP:
mp11.stop();
mp11.release();
break;
}return true;
}
private boolean stop()
{
mp1.stop();
// TODO: Implement this method
return true;
}
});
bu2.setOnTouchListener(new OnTouchListener(){
@Override
public boolean onTouch(View p1, MotionEvent p2){
switch(p2.getActionMasked()){
case MotionEvent.ACTION_DOWN:
mp1=MediaPlayer.create(MainActivity.this,R.raw.la1);
mp1.start();
mp1.setLooping(true);
mp1.setVolume(100,100);
break;
case MotionEvent.ACTION_UP:
mp1.stop();
mp1.release();
break;
}
return true;
}
});