package com.yidianling.muse.utils

class MediaPlayerTimeUtil {

    companion object{

        fun calculateTime(time:Int):String?{
            var minute = 0
            var second = 0
            if (time>60){
                minute = time / 60
                second = time % 60
                return if (minute in 0..9){
                    if (second in 0..9){
                        "0$minute:0$second"
                    }else{
                        "0$minute:$second"
                    }
                }else{
                    if (second in 0..9){
                        "$minute:0$second"
                    }else{
                        "$minute:$second"
                    }
                }
            }else if (time<60){
                second = time
                return if (second in 0..9){
                    "00:0$second"
                }else{
                    "00:$second"
                }
            }
            return null
        }

        fun formatTimeOff(finishTime:Long):String{

            var totalTime = (finishTime / 1000).toInt() //秒

            var minute = 0
            var second = 0

            if (60 <= totalTime) {
                minute = totalTime / 60
                totalTime -= 60 * minute
            }
            if (0 <= totalTime) {
                second = totalTime
            }
            val sb = StringBuilder()

            if (minute < 10) {
                sb.append("0").append(minute).append(":")
            } else {
                sb.append(minute).append(":")
            }
            if (second < 10) {
                sb.append("0").append(second)
            } else {
                sb.append(second)
            }
            return sb.toString()

        }

    }

}