how is it going? Could someone tell me what I would have to do to make the sound stop ringing until I left the button? Try the motion.event actiondown and actionup but the full sound sounds, but I just want it to play until the user releases the touch button? .. I do not know if he has to see the sound (sample) that is in .ogg format ... and I understand that with the media player method it is for long sounds and soundpool for short films ...
public class MainActivity extends AppCompatActivity {
ImageButton imTecla29,imTecla30;
private SoundPool soundPool;
private int sonTecla29, sonTecla30;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
//ORIENTACION
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
imTecla29=(ImageButton)findViewById(R.id.tecla1);
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
soundPool =new SoundPool.Builder().setMaxStreams(5).build();
}else {
soundPool= new SoundPool(5, AudioManager.STREAM_MUSIC,0);
}
sonTecla29=soundPool.load(this, R.raw.acor29,1);
imTecla29.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View view, MotionEvent motionEvent) {
if(motionEvent.getAction()==MotionEvent.ACTION_DOWN){
soundPool.play(sonTecla29,1,1,0,0,0);
}else if(motionEvent.getAction()== MotionEvent.ACTION_UP)
soundPool.stop();
return false;
}
});