listview - Correct play/stop mediaplayer android -



listview - Correct play/stop mediaplayer android -

i have list view , mediaplayer utilize play sounds based on row position (like soundboard). problem when sound playing, , row clicked (different position in list view), stop sound , start new sound. code, works fine on play/stop on same row, not on different rows. how can prepare that?

public void playsound(int pos){ if(isplaying && mmediaplayer.isplaying()){ mmediaplayer.stop(); mmediaplayer.release(); mmediaplayer = null; play.setimagedrawable(context.getresources().getdrawable(r.drawable.play)); play.invalidate(); isplaying = false; } else{ mmediaplayer = mediaplayer.create(context, songs[pos]); mmediaplayer.start(); isplaying = true; play.setimagedrawable(context.getresources().getdrawable(r.drawable.stop)); play.invalidate(); mmediaplayer.setoncompletionlistener(new oncompletionlistener() { public void oncompletion(mediaplayer mp) { isplaying = false; play.setimagedrawable(context.getresources().getdrawable(r.drawable.play)); play.invalidate(); } }); } }

this onclick() method:

@override public view getview(final int position, view convertview, viewgroup parent) { // todo auto-generated method stub view vi = convertview; vi.setonclicklistener(new onclicklistener() { @override public void onclick(view v) { play = (imagebutton) v.findviewbyid(r.id.imageplay); playsound(position); } });

android listview android-mediaplayer

Comments

Popular posts from this blog

formatting - SAS SQL Datepart function returning odd values -

c++ - Apple Mach-O Linker Error(Duplicate Symbols For Architecture armv7) -

php - Yii 2: Unable to find a class into the extension 'yii2-admin' -