android - Get current postion from videoview in Time format -
i writing application trim videos in android using ffmpeg
. need give values ffmpeg
in time units 00:00:10
. have videoview
, 2 buttons
. first button starttime
, second button endtime
. when ever button clicked use getcurrentposition
current position of video. have mediacontroller
attached videoview
.
now problem facing int
value of current position cannot pass ffmpeg
how accurately convert value in time units, can pass ffmpeg
trim video. have given code below reference. there other way current time other this. in advance.
tvideoview = (videoview) findviewbyid(r.id.tvideoview); startbtn = (button) findviewbyid(r.id.tstartbtn); endbtn = (button) findviewbyid(r.id.tendbtn); trimbtn = (button) findviewbyid(r.id.trimbtn); tvideoview.setvideopath(videopath); duration = tvideoview.getduration(); mmedia = new mediacontroller(this); mmedia.setmediaplayer(tvideoview); mmedia.setanchorview(tvideoview); tvideoview.setmediacontroller(mmedia); startbtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { starttime = tvideoview.getcurrentposition(); startbtn.settext(string.valueof(starttime)); } }); endbtn.setonclicklistener(new view.onclicklistener() { @override public void onclick(view v) { endtime = tvideoview.getcurrentposition(); endbtn.settext(string.valueof(endtime)); } });
you can use simple method milliseconds time in date format,
/** * return date in specified format. * @param milliseconds date in milliseconds * @param dateformat date format * @return string representing date in specified format */ public static string getdate(long milliseconds, string dateformat) { // create dateformatter object displaying date in specified format. simpledateformat formatter = new simpledateformat(dateformat); // create calendar object convert time value in milliseconds date. calendar calendar = calendar.getinstance(); calendar.settimeinmillis(milliseconds); return formatter.format(calendar.gettime()); }
to call method,
string time = (getdate(12184, "hh:mm:ss"));
this return standard time format like, 06:00:12
Comments
Post a Comment