android - MediaPlayer Issue? -
i'm developing simple piano app own interest. problem when press key, have wait until sound finished play again same key! there way play key , not wait until sound finished?
whitekey2 = (button)rootview.findviewbyid(r.id.button3); final mediaplayer d4 = mediaplayer.create(getactivity(), r.raw.d4); whitekey2.setontouchlistener(new ontouchlistener(){ @override public boolean ontouch(view v, motionevent event) { // todo auto-generated method stub switch (event.getaction()){ case motionevent.action_down: d4.start(); case motionevent.action_up: } return false; }
give try
whitekey2 = (button)rootview.findviewbyid(r.id.button3); whitekey2.setontouchlistener(new ontouchlistener(){ @override public boolean ontouch(view v, motionevent event) { // todo auto-generated method stub switch (event.getaction()){ case motionevent.action_down: mediaplayer.create(getactivity(), r.raw.d4).start(); case motionevent.action_up: } return false; }
creating new mediaplayer on each press should allow create multiple sounds. careful deallocating memory however, end leaving many mediaplayers laying around...
Comments
Post a Comment