在 exoplayer 2.11.8 中查找当前窗口实时时间

发布于 2025-01-11 05:54:41 字数 458 浏览 2 评论 0原文

我正在尝试获取 expolaer 版本 2.11.8 中的当前窗口实时时间

到目前为止,从不同的参考文献和链接中我能够得出这个

 fun BasePlayer.getLivePosition(): Long {
    var position: Long = currentPosition
    if (!currentTimeline.isEmpty) {
        position -= currentTimeline.getPeriod(currentPeriodIndex, Timeline.Period())
            .positionInWindowMs
    }
    return position
}

它确实给了我位置,但我无法将其转换为米尔斯的当前时间。 我想要格式为 yyyy-MM-dd'T'HH:mm:ss.SSS'Z' 的实时窗口时间

I am trying to get the current window live time in expolayer version 2.11.8

So far from different references and links I was able to come up with this

 fun BasePlayer.getLivePosition(): Long {
    var position: Long = currentPosition
    if (!currentTimeline.isEmpty) {
        position -= currentTimeline.getPeriod(currentPeriodIndex, Timeline.Period())
            .positionInWindowMs
    }
    return position
}

It does gives me the position but I am not able to convert it to current time in mills.
I want the live window time in format yyyy-MM-dd'T'HH:mm:ss.SSS'Z'

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

心清如水 2025-01-18 05:54:41

我能够进入2.13以上的exoplayer版本

fun getPlayerCurrentTime(
    _playerID: ExoPlayer): String? {
    val playerOffsetDateFormat = "yyyy-MM-dd"
    simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z")
    simpleDateFormat!!.timeZone = TimeZone.getTimeZone("UTC")
   
    val window: Timeline.Window = Timeline.Window()
    val wTime = window.currentUnixTimeMs
   val  playerOffsetTime = _playerID.currentLiveOffset
    offsetDateFormat = SimpleDateFormat(playerOffsetDateFormat)
    offsetDateFormat!!.timeZone = TimeZone.getTimeZone("UTC")
    val dateForOffset = offsetDateFormat!!.format(Date())
    convertPlayerOfffsetDate = Date(playerOffsetTime!!)
    formatter = SimpleDateFormat("HH:mm:ss Z")
    formatter!!.timeZone = TimeZone.getTimeZone("UTC")
    dateFormatted = formatter!!.format(convertPlayerOfffsetDate)
    concatOffsetFormat = dateForOffset + " " + dateFormatted
    val destDf: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z")
    val dateFF = concatOffsetFormat
    val format111: DateFormat =
        SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.ENGLISH)
    val dateff = format111.parse(dateFF)
    val targetDate = destDf.format(dateff)
    val d1 = simpleDateFormat!!.parse(targetDate)
    val d2 =
        simpleDateFormat!!.parse(simpleDateFormat!!.format(Date(wTime)))

    val d1d2 = d2.time - d1.time
    val datex = Date(d1d2)
    val formatterx: DateFormat = SimpleDateFormat("HH:mm:ss Z")
    formatterx.timeZone = TimeZone.getTimeZone("UTC")
    val dateFormattedx: String = formatterx.format(datex)
    currentPlayerTime = dateForOffset + " " + dateFormattedx

    val inputFormat1 =
        SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z")
    val outputFormat1 = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
    outputFormat1.timeZone = TimeZone.getTimeZone("UTC")
    val datee1 = inputFormat1.parse(currentPlayerTime)
    currentPlayerTime = outputFormat1.format(datee1)
    return currentPlayerTime
}

I was able to get in the exoplayer version above 2.13

fun getPlayerCurrentTime(
    _playerID: ExoPlayer): String? {
    val playerOffsetDateFormat = "yyyy-MM-dd"
    simpleDateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z")
    simpleDateFormat!!.timeZone = TimeZone.getTimeZone("UTC")
   
    val window: Timeline.Window = Timeline.Window()
    val wTime = window.currentUnixTimeMs
   val  playerOffsetTime = _playerID.currentLiveOffset
    offsetDateFormat = SimpleDateFormat(playerOffsetDateFormat)
    offsetDateFormat!!.timeZone = TimeZone.getTimeZone("UTC")
    val dateForOffset = offsetDateFormat!!.format(Date())
    convertPlayerOfffsetDate = Date(playerOffsetTime!!)
    formatter = SimpleDateFormat("HH:mm:ss Z")
    formatter!!.timeZone = TimeZone.getTimeZone("UTC")
    dateFormatted = formatter!!.format(convertPlayerOfffsetDate)
    concatOffsetFormat = dateForOffset + " " + dateFormatted
    val destDf: DateFormat = SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z")
    val dateFF = concatOffsetFormat
    val format111: DateFormat =
        SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z", Locale.ENGLISH)
    val dateff = format111.parse(dateFF)
    val targetDate = destDf.format(dateff)
    val d1 = simpleDateFormat!!.parse(targetDate)
    val d2 =
        simpleDateFormat!!.parse(simpleDateFormat!!.format(Date(wTime)))

    val d1d2 = d2.time - d1.time
    val datex = Date(d1d2)
    val formatterx: DateFormat = SimpleDateFormat("HH:mm:ss Z")
    formatterx.timeZone = TimeZone.getTimeZone("UTC")
    val dateFormattedx: String = formatterx.format(datex)
    currentPlayerTime = dateForOffset + " " + dateFormattedx

    val inputFormat1 =
        SimpleDateFormat("yyyy-MM-dd HH:mm:ss Z")
    val outputFormat1 = SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS'Z'")
    outputFormat1.timeZone = TimeZone.getTimeZone("UTC")
    val datee1 = inputFormat1.parse(currentPlayerTime)
    currentPlayerTime = outputFormat1.format(datee1)
    return currentPlayerTime
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文