java - How to play, stop and pause working on media player instance in android ? -


i want develop media player type of application has 2 button 1 play , pause , 1 stop. take 2 image buttons in layout file , reference in java file , code put here, when click on stop button audio getting stopped want replay audio file; cant play play button.

my java code below

public view oncreateview(layoutinflater inflater, viewgroup container,             bundle savedinstancestate) {         view v = inflater.inflate(r.layout.activity_aarti_fragment, container, false);          btnplay=(imagebutton)v.findviewbyid(r.id.btnplay);         btnstop=(imagebutton)v.findviewbyid(r.id.btnstop);         seekbar=(seekbar)v.findviewbyid(r.id.seekbar);          mp = mediaplayer.create(getactivity(), r.raw.arti);         btnstop.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                 mp.stop();                 btnplay.setimageresource(r.drawable.ic_action_play);                 toast.maketext(getactivity(), "stop",toast.length_long).show();              }         });         btnplay.setonclicklistener(new onclicklistener() {              @override             public void onclick(view v) {                  if(mp.isplaying())                 {                     mp.pause();                     btnplay.setimageresource(r.drawable.ic_action_play);                     toast.maketext(getactivity(), "pause",toast.length_short).show();                 }                 else                 {   btnplay.setimageresource(r.drawable.ic_action_pause);                     mp.start();                     toast.maketext(getactivity(), "play",toast.length_short).show();                 }             }         });          return v;     } 

once media player stopped, need call prepare on again state can call start(). @ state diagram here http://developer.android.com/reference/android/media/mediaplayer.html#pause%28%29


Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -