实习入职第十二天:MediaPlayer时间之间的转换函数

/**
* 计算连个时间之间的秒数
*/

private static int totalSeconds(String startTime, String endTime) {

String[] st = startTime.split(":");
String[] et = endTime.split(":");

int st_h = Integer.valueOf(st[0]);
int st_m = Integer.valueOf(st[1]);
int st_s = Integer.valueOf(st[2]);

int et_h = Integer.valueOf(et[0]);
int et_m = Integer.valueOf(et[1]);
int et_s = Integer.valueOf(et[2]);

int totalSeconds = (et_h - st_h) * 3600 + (et_m - st_m) * 60
+ (et_s - st_s);

return totalSeconds;

}

/**
* 根据当前选择的秒数还原时间点

* @param args
*/

private static String getCheckTimeBySeconds(int progress, String startTime) {

String return_h = "", return_m = "", return_s = "";

String[] st = startTime.split(":");

int st_h = Integer.valueOf(st[0]);
int st_m = Integer.valueOf(st[1]);
int st_s = Integer.valueOf(st[2]);

int h = progress / 3600;

int m = (progress % 3600) / 60;

int s = progress % 60;

if ((s + st_s) >= 60) {

int tmpSecond = (s + st_s) % 60;

m = m + 1;

if (tmpSecond >= 10) {
return_s = tmpSecond + "";
} else {
return_s = "0" + (tmpSecond);
}

} else {
if ((s + st_s) >= 10) {
return_s = s + st_s + "";
} else {
return_s = "0" + (s + st_s);
}

}

if ((m + st_m) >= 60) {

int tmpMin = (m + st_m) % 60;

h = h + 1;

if (tmpMin >= 10) {
return_m = tmpMin + "";
} else {
return_m = "0" + (tmpMin);
}

} else {
if ((m + st_m) >= 10) {
return_m = (m + st_m) + "";
} else {
return_m = "0" + (m + st_m);
}

}

if ((st_h + h) < 10) {
return_h = "0" + (st_h + h);
} else {
return_h = st_h + h + "";
}

return return_h + ":" + return_m + ":" + return_s;
}

}


public static String getStandardTime(int time) {
time = time/1000;
int h = time / 1000 / 60 / 24;
int m = (time - h * 1000 * 60 * 24) / 1000 / 60;
int s = (time - h * 1000 * 60 * 24 - m * 1000 * 60);
if(time<0){
return "00:00";
}else if(isNum(h)){
return hasTwo(m)+":"+hasTwo(s);
}else{
return hasTwo(h)+":"+hasTwo(m)+":"+hasTwo(s);
}
}

public static boolean isNum(int n){
if (n==0)
return true;
else
return false;
}


public static String hasTwo(int n) {
if ((n >= 10 && n <= 99))
return n+"";
else
return "0"+n;
}

阅读更多
文章标签: 实习
个人分类: 实习
上一篇实习入职第十一天:MediaPlayer怎么拿到视频的时长
下一篇实习入职第十二天:Android中Bitmap,byte[],Drawable,InputStream相互转化工具类
想对作者说点什么? 我来说一句

没有更多推荐了,返回首页

关闭
关闭