浏览代码

合成页增加播放时间显示

harry 3 年之前
父节点
当前提交
fd8aed48b3
共有 1 个文件被更改,包括 28 次插入2 次删除
  1. 28 2
      Introduce/Record/INVideoExportController.swift

+ 28 - 2
Introduce/Record/INVideoExportController.swift

@@ -69,6 +69,20 @@ class INVideoExportController: BFBaseViewController {
         return la
     }()
 
+    // 播放进度显示
+    lazy var playDurL: UILabel = {
+        let la = UILabel()
+        la.textAlignment = .center
+        la.font = UIFont.systemFont(ofSize: 12, weight: .medium)
+        la.textColor = .white
+        la.layer.shadowOpacity = 0.4
+        la.layer.shadowColor = UIColor.black.cgColor
+        la.layer.shadowOffset = CGSize(width: 0, height: 2)
+        la.layer.shadowRadius = 2
+        la.text = "00:00/00:00"
+        return la
+    }()
+    
     lazy var saveAllBtn: UIButton = {
         let btn = UIButton()
         btn.setImage(UIImage(named: "export_saveall_n"), for: .normal)
@@ -176,14 +190,16 @@ class INVideoExportController: BFBaseViewController {
     var playerLayer: AVPlayerLayer!
     lazy var avplayer: AVPlayer = {
         let avplayer = AVPlayer()
-        avplayerTimeObserver = avplayer.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 100), queue: DispatchQueue.global()) { [weak self, weak avplayer] _ in
+        avplayerTimeObserver = avplayer.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 10), queue: DispatchQueue.global()) { [weak self, weak avplayer] time in
             //    进度监控
             if let item = avplayer?.currentItem, !(self?.sliderView?.isDragingProgressSlder ?? false) {
                 DispatchQueue.main.async { [weak self, weak avplayer] in
                     if avplayer?.currentItem?.status != .readyToPlay {
+                        self?.playDurL.text = "00:00/00:00"
                         self?.sliderView?.progress = 0
                     }else{
-                        self?.sliderView?.progress = CMTimeGetSeconds(item.currentTime()) / CMTimeGetSeconds(item.duration)                        
+                        self?.playDurL.text = String(format: "%@ / %@", CMTimeGetSeconds(time).formatDurationToHMS(), CMTimeGetSeconds(item.duration).formatDurationToHMS())
+                        self?.sliderView?.progress = CMTimeGetSeconds(item.currentTime()) / CMTimeGetSeconds(item.duration)
                     }
                 }
             }
@@ -228,6 +244,7 @@ class INVideoExportController: BFBaseViewController {
                 sself.progressL.text = "0%"
                 if let fileUrl = url {
                     sself.sliderView?.isHidden = false
+                    sself.playDurL.isHidden = false
                     sself.sliderView?.playStart()
                     sself.completeBtn.isHidden = false
 
@@ -393,6 +410,7 @@ class INVideoExportController: BFBaseViewController {
         backV.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(playAction)))
         
         backV.addSubview(coverIV)
+        backV.addSubview(playDurL)
         backV.addSubview(progressView)
         backV.addSubview(progressL)
         
@@ -410,6 +428,13 @@ class INVideoExportController: BFBaseViewController {
             make.width.equalTo(coverIV.snp.height).multipliedBy(cScreenWidth / cScreenHeigth)
             make.height.equalToSuperview().offset(-1 * cDevice_iPhoneNavBarAndStatusBarHei + 30)
         }
+        
+        playDurL.snp.makeConstraints { make in
+            make.width.centerX.equalTo(coverIV)
+            make.top.equalTo(coverIV).offset(5)
+            make.height.equalTo(20)
+        }
+        
         progressView.snp.makeConstraints { make in
             make.top.left.bottom.equalTo(coverIV)
             make.width.equalTo(0)
@@ -570,6 +595,7 @@ class INVideoExportController: BFBaseViewController {
         progressView.isHidden = false
         progressL.isHidden = false
         sliderView?.isHidden = true
+        playDurL.isHidden = true
         
         DispatchQueue.global().async {[weak self] in
             self?.export.startExprot(synthesisAll: self?.saveAllBtn.isSelected ?? true)