2017-05-26 98 views
1

我正在創建一個項目,我想在標籤中顯示當前時間。如何更改標籤樣式CMTimeGetSeconds

我用CMTimeGetSeconds以編程方式設置了定時器和標籤來跟蹤秒。

我想刪除超過10分鐘的電話號碼(因爲視頻長度只有2分鐘)。

這是什麼方法?

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)" 


      }) 
+0

可以顯示分鐘前檢查條件。 – KKRocks

回答

0

嘿,你需要做的條件代碼。 - 雨燕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