gpt4 book ai didi

swift - AVPlayer 中耗时在 swift 中显示奇怪的数字

转载 作者:行者123 更新时间:2023-11-30 13:32:27 35 4
gpt4 key购买 nike

我有以下代码来尝试显示我的音频文件的耗时:

    func updateTime() {
let currentTime = Int(player!.currentTime().value)
let minutes = currentTime/60
print(minutes)
let seconds = currentTime - minutes * 60
print(seconds)
time.text = NSString(format: "%02d:%02d", minutes,seconds) as String
}

计时器在此代码中的 View “已加载”中设置:

    play.play()

timer = NSTimer.scheduledTimerWithTimeInterval(1.0, target: self, selector: #selector(.updateTime), userInfo: nil, repeats: true)

标签中显示数字,但它们完全是随机的,因此不显示秒和分钟。我在这里做错了什么?这是我获取当前时间的方式吗?

最佳答案

我将此行更改为:

let currentTime = Int(player!.currentTime().value) / Int(player!.currentTime().timescale)

我不知道为什么会这样,但它确实有效!

关于swift - AVPlayer 中耗时在 swift 中显示奇怪的数字,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36415625/

35 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com