如何更改标签样式CMTimeGetSeconds

时间:2017-05-26 04:37:35

标签: ios swift video

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

我已使用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)"


            })

1 个答案:

答案 0 :(得分:1)

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

$users = Users::with(['profiles' => function ($query) {
    $query->where('country', 'USA');
    $query->orWhere('country', 'Poland')
}])->get();
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);
                }
            }
        }
    }