java - App stops unexpectedly when using OnTouchListener, MotionEvent.ACTION_UP -
so want create buttons play music long pressed, once released, music stops.
in createlisteners()
, have following:
b1.setontouchlistener(new view.ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { if(event.getaction() == motionevent.action_down) { startbeat(1, m1); return true; } else if (event.getaction() == motionevent.action_up) { m1.stop(); } return false; } });
m1
mediaplayer
, , in method startbeat
, m1.start()
has been called.
when running app, music plays fine, long don't release button. however, moment release button, app says stopped unexpectedly. causing problem?
is there way go implementing feature?
maybe try play again mediaplayer
??
calling stop() stops playback , causes mediaplayer in started, paused, prepared or playbackcompleted state enter stopped state. once in stopped state, playback cannot started until prepare() or prepareasync() called set mediaplayer object prepared state again.
if don't, try m1.pause();
, m1.seekto(0)
simulate stop...
public boolean ontouch(view v, motionevent event) { if(event.getaction() == motionevent.action_down) { startbeat(1, m1); return true; } else if (event.getaction() == motionevent.action_up) { m1.pause(); m1.seekto(0); return true; } return false; }
Comments
Post a Comment