gpt4 book ai didi

ios - 如何更改标签样式 CMTimeGetSeconds

转载 作者:行者123 更新时间:2023-11-28 06:19:16 25 4
gpt4 key购买 nike

我正在创建一个项目,我想在标签中显示当前时间。

我已使用 CMTimeGetSeconds 以编程方式设置计时器和标签以跟踪秒数。

我想删除超过 10 分钟的数字(因为视频的长度只有两分钟)。

这样做的好方法是什么?

enter image description here

let currentTimeLabel: UILabel = {
let label = UILabel()
label.translatesAutoresizingMaskIntoConstraints = false
label.text = "0:00"
return label
}()

fileprivate func setupPlayerView() {

player?.addObserver(self, forKeyPath: "currentItem.loadedTimeRanges", options: .new, context: nil)

/track player progress

let interval = CMTime(value: 1, timescale: 2)
player?.addPeriodicTimeObserver(forInterval: interval, queue: DispatchQueue.main, using: { (progressTime) in

let seconds = CMTimeGetSeconds(progressTime)
let secondsString = String(format: "%02d", Int(seconds.truncatingRemainder(dividingBy: 60)))
let minutesString = String(format: "%02d", Int(seconds / 60))

self.currentTimeLabel.text = "\(minutesString):\(secondsString)"


})

最佳答案

嘿,你需要做条件代码。- Swift 3.0 代码

let timeDuration : TimeInterval =  60.0 //Recording time
var incrementPrgVal : Float = 0.1 //DEFUALT VALUE
var startTimeIncrementSec : Float64 = 1

private func updateStartTime()
{
if self.audioRecorder != nil {
startTimeIncrementSec = startTimeIncrementSec + 1;
if(startTimeIncrementSec > timeDuration){
return;
}
if(startTimeIncrementSec < 60)
{
let valSec = fmod(startTimeIncrementSec, 60);
if(valSec < 10){
self.objOverlayView.lblStartTime.text = String(format: "00:0%.0f",valSec);
}
else{
self.objOverlayView.lblStartTime.text = String(format: "00:%.0f",valSec);
}
}
else{

let secondPresion = fmod(startTimeIncrementSec, 60)
let presionTime = (startTimeIncrementSec/60)
if(secondPresion < 10){
self.objOverlayView.lblStartTime.text = String(format: "%.0f:0%.0f",presionTime,secondPresion);
}
else{
self.objOverlayView.lblStartTime.text = String(format: "%.0f:%.0f",presionTime ,secondPresion);
}
}
}
}
This is basic snippet of code

关于ios - 如何更改标签样式 CMTimeGetSeconds,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44193716/

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