How do i update Seekbar mp3 progress every second with a thread?(code/pics included) Android -


im trying seekbar update , show progress whenever play mp3 mediaplayer. music plays fine everytime, seekbar snap 0 position when mp3 playing.

i trying follow answer wont work... seekbar , media player in android

i have code in main activity

private handler mhandler = new handler(); mainactivity.this.runonuithread(new runnable() {          @override         public void run() {             if (assets.mediaplayer != null) {                 int mcurrentposition = assets.mediaplayer.getcurrentposition() / 1000;                 if(onionfragment.seekbar!= null) {                     onionfragment.seekbar.setprogress(mcurrentposition);                 }             }             mhandler.postdelayed(this, 1000);         }     }); 

in onionfragment have

public static seekbar seekbar; seekbar = (seekbar) rootview.findviewbyid(r.id.seekbar); 

and in onionfragments onclick (the play button)i have

assets.playmusicfile(mainactivity.items.get(mainactivity.selecteditem).getsongid(), true);                 if(assets.mediaplayer!=null) {                     seekbar.setmax(assets.mediaplayer.getduration());                 } 

onionfragment loaded mainactivity right away , looks this

p.s. if has time, how change size of seekbar ball , color

change

seekbar.setmax(assets.mediaplayer.getduration()); 

to

seekbar.setmax(assets.mediaplayer.getduration()/1000); 

Comments

Popular posts from this blog

toolbar - How to add link to user registration inside toobar in admin joomla 3 custom component -

linux - disk space limitation when creating war file -