MediaPlayerTimeUtil.kt 2.76 KB
Newer Older
范玉宾 committed
1 2
package com.yidianling.muse.utils

3 4 5 6 7
import com.ydl.ydlcommon.data.http.ThrowableConsumer
import com.yidianling.home.http.MuseHttp
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers

范玉宾 committed
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
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"
                    }
                }
31
            }else if (time in 0..59){
范玉宾 committed
32 33 34 35 36 37 38
                second = time
                return if (second in 0..9){
                    "00:0$second"
                }else{
                    "00:$second"
                }
            }
范玉宾 committed
39
            return ""
范玉宾 committed
40 41
        }

范玉宾 committed
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71
        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()

        }

72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94
        fun uploadPlayRecord(meditationId:Int?,mediaId:Long?,
            isQuit:Int,playTime:Int,isComplete:Int){
            if (meditationId != null && mediaId != null) {
                MuseHttp.getInstance().postMeditationPlayRecord(
                    meditationId = meditationId!!.toInt(),
                    isQuit = isQuit, mediaId = mediaId!!,
                    playTime = playTime,
                    isComplete = isComplete
                )
                    .subscribeOn(Schedulers.io())
                    .observeOn(AndroidSchedulers.mainThread())
                    .subscribe({

                    }, {
                        object : ThrowableConsumer() {
                            override fun accept(msg: String) {

                            }
                        }
                    })
            }
        }

范玉宾 committed
95 96 97
    }

}