Android Sync video with timer -


i'm using android construct video player using videoview. i've managed video player running , i'm setting counter using chronometer starts ticking when select file.
however, video clip takes few seconds start running while timer has begun counting few seconds when clip starts.

how can code sync counter media file?
i've checked around can't seem find answer.

    video = (videoview) findviewbyid(r.id.video);     play = (button) findviewbyid(r.id.play);     pause = (button) findviewbyid(r.id.pause);     stop = (button) findviewbyid(r.id.stop);     reset = (button) findviewbyid(r.id.reset);     chronometer counter = (chronometer) findviewbyid(r.id.chrono);     starttime = systemclock.elapsedrealtime();     time = (textview) findviewbyid(r.id.time);          try {         video.setvideopath(link);         video.start();         video.requestfocus();     } catch (illegalargumentexception e) {         e.printstacktrace();     } catch (illegalstateexception e) {         e.printstacktrace();     }      play.setonclicklistener(new onclicklistener() {         public void onclick(view v) {             video.start();             video.requestfocus();         }     });     pause.setonclicklistener(new onclicklistener() {         public void onclick(view v) {             video.pause();         }     });     stop.setonclicklistener(new onclicklistener() {         public void onclick(view v) {             try {                 video.stopplayback();                 video.setvideopath(link);             } catch (illegalstateexception e) {                 e.printstacktrace();             }         }     });     reset.setonclicklistener(new onclicklistener() {         public void onclick(view v) {             try {                 video.seekto(0);                 video.start();                 video.requestfocus();             } catch (illegalstateexception e) {                 e.printstacktrace();             }         }     });  counter.setonchronometerticklistener(new onchronometerticklistener(){         public void onchronometertick(chronometer arg0) {             countup = (systemclock.elapsedrealtime() - arg0.getbase()) / 1000;             duration = video.getduration();             if (countup % 60 <= 9) {                 counttext = (countup / 60) + ":0" + (countup % 60);             } else {                 counttext = (countup / 60) + ":" + (countup % 60);                        }              if (duration % 60000 <= 9) {                 durationtext = (duration / 60000) + ":0" + (duration % 60000);             } else {                 durationtext = (duration / 60000) + ":" + (duration % 60000);                        }             time.settext(counttext + " / " + durationtext);         }     });     counter.start(); 

no worries, found way use videoview getcurrentposition() in chronometer. sees correct current time , easier keep check of.

counter.setonchronometerticklistener(new onchronometerticklistener(){         public void onchronometertick(chronometer arg0) {             countup = video.getcurrentposition();             countup = math.round(countup / 1000);             duration = video.getduration();             duration = duration / 1000;             long = (long) countup;             if (countup % 60000 <= 9) {                 counttext = (a / 60000) + ":0" + (a % 60000);             } else {                 counttext = (a / 60000) + ":" + (a % 60000);                        }              if (duration % 60000 <= 9) {                 durationtext = (duration / 60000) + ":0" + (duration % 60000);             } else {                 durationtext = (duration / 60000) + ":" + (duration % 60000);                        }             time.settext(counttext + " / " + durationtext);         }     });     counter.start(); 

Comments

Popular posts from this blog

java - SNMP4J General Variable Binding Error -

windows - Python Service Installation - "Could not find PythonClass entry" -

Determine if a XmlNode is empty or null in C#? -