diff --git a/common/src/main/java/com/yunbao/common/utils/StringUtil.java b/common/src/main/java/com/yunbao/common/utils/StringUtil.java index 0883d8b30..96b6698ba 100644 --- a/common/src/main/java/com/yunbao/common/utils/StringUtil.java +++ b/common/src/main/java/com/yunbao/common/utils/StringUtil.java @@ -120,6 +120,33 @@ public class StringUtil { return sStringBuilder.toString(); } + /** + * 把一个long类型的总毫秒数转成时长 + */ + public static String getDurationText2(long mms) { + int minutes = (int) ((mms % (1000 * 60 * 60)) / (1000 * 60)); + int seconds = (int) ((mms % (1000 * 60)) / 1000); + sStringBuilder.delete(0, sStringBuilder.length()); + if (minutes > 0) { + if (minutes < 10) { + sStringBuilder.append("0"); + } + sStringBuilder.append(String.valueOf(minutes)); + sStringBuilder.append(":"); + } else { + sStringBuilder.append("00:"); + } + if (seconds > 0) { + if (seconds < 10) { + sStringBuilder.append("0"); + } + sStringBuilder.append(String.valueOf(seconds)); + } else { + sStringBuilder.append("00"); + } + return sStringBuilder.toString(); + } + /** * 设置视频输出路径 diff --git a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java index 30a5ec967..a977300b8 100644 --- a/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java +++ b/live/src/main/java/com/yunbao/live/presenter/LiveSwLinkMicPkPresenter.java @@ -331,7 +331,7 @@ public class LiveSwLinkMicPkPresenter extends AbsLinkMicPkPresenter implements V } if (mLiveLinkMicPkViewHolder != null) { String s = mIsPkEnd ? mPkTimeString2 : mPkTimeString1; - String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); + String s1 = StringUtil.getDurationText2(mPkTimeCount * 1000); Log.i("tag23333", mPkTimeCount + "mPkTimeCount" + s1 + "is" + is); if (i == 1 && s1.equals("00:01")) { s1 = "00:00"; @@ -1729,11 +1729,11 @@ public class LiveSwLinkMicPkPresenter extends AbsLinkMicPkPresenter implements V layoutParams.topMargin = DpUtil.dp2px(165); livePushSwViewHolder.timeTitle.setLayoutParams(layoutParams); livePushSwViewHolder.timeTitle.setVisibility(View.VISIBLE); - String pkTime = StringUtil.getDurationText(time * 1000); + String pkTime = StringUtil.getDurationText2(time * 1000); livePushSwViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), pkTime)); mPkTimeCount = time; if (time > 0) { - String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); + String s1 = StringUtil.getDurationText2(mPkTimeCount * 1000); livePushSwViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); mHandler.sendEmptyMessage(WHAT_PK_TIME2); } @@ -1989,7 +1989,7 @@ public class LiveSwLinkMicPkPresenter extends AbsLinkMicPkPresenter implements V mPkTimeCount--; if (mPkTimeCount > 0) {// if (mHandler != null) { - String s1 = StringUtil.getDurationText(mPkTimeCount * 1000); + String s1 = StringUtil.getDurationText2(mPkTimeCount * 1000); livePushSwViewHolder.textTime.setText(String.format(mContext.getString(R.string.pk_time), s1)); mHandler.sendEmptyMessageAtTime(WHAT_PK_TIME2, getNextSecondTime()); }