android - how to stop audio from playing when image has been touched -
i have got imageview when user taps image audio starts playing, , works great here code that:
final imageview imageview = (imageview) findviewbyid(r.id.image7); imageview.setimageresource(mfullsizeids[position]); imageview.setontouchlistener(new ontouchlistener() { @override public boolean ontouch(view v, motionevent event) { mediaplayer mp = mediaplayer.create(audio.this,maudio[position]); mp.start(); return false; } });
now when want user touch image again audio should stop. have added code:
if (mp != null && mp.isplaying()) mp.stop(); return false; } });
but sound doesn't play. confused logic tells me should work. doing wrong here? please help...
not quite sure mean block code?
did call function prepare
or prepareasync
on media?
then, when stoping media, think must reset
it.
Comments
Post a Comment