|
@@ -14,6 +14,18 @@ import BFRecordScreenKit
|
|
class INVideoExportController: BFBaseViewController {
|
|
class INVideoExportController: BFBaseViewController {
|
|
|
|
|
|
var videoAsset : AVURLAsset?
|
|
var videoAsset : AVURLAsset?
|
|
|
|
+ var avplayerTimeObserver: NSKeyValueObservation?
|
|
|
|
+
|
|
|
|
+ lazy var progreddL : UILabel = {
|
|
|
|
+ let l = UILabel(frame: CGRect(x: 0, y: cDevice_iPhoneStatusBarHei, width: cScreenWidth, height: 14))
|
|
|
|
+ l.textAlignment = .center
|
|
|
|
+ l.font = UIFont.systemFont(ofSize: 10)
|
|
|
|
+ l.textColor = .white
|
|
|
|
+ l.shadowColor = .black
|
|
|
|
+ l.shadowOffset = CGSize(width: 1, height: 1)
|
|
|
|
+ return l
|
|
|
|
+ }()
|
|
|
|
+
|
|
|
|
|
|
lazy var progressView : UIView = {
|
|
lazy var progressView : UIView = {
|
|
let v = UIView(frame: CGRect(x: 0, y: navHeadImageView!.bottomY, width: 0, height: 10))
|
|
let v = UIView(frame: CGRect(x: 0, y: navHeadImageView!.bottomY, width: 0, height: 10))
|
|
@@ -30,6 +42,23 @@ class INVideoExportController: BFBaseViewController {
|
|
return la
|
|
return la
|
|
}()
|
|
}()
|
|
|
|
|
|
|
|
+ lazy var avplayer : AVPlayer = {
|
|
|
|
+ let avplayer = AVPlayer()
|
|
|
|
+ avplayerTimeObserver = avplayer.addPeriodicTimeObserver(forInterval: CMTime(value: 1, timescale: 100), queue: DispatchQueue.global()) {[weak self, weak avplayer] time in
|
|
|
|
+ // 进度监控
|
|
|
|
+ if let item = avplayer?.currentItem {
|
|
|
|
+ self?.progreddL.text = String(format: "%.2f / %.2f", CMTimeGetSeconds(time), CMTimeGetSeconds(item.duration))
|
|
|
|
+
|
|
|
|
+ }
|
|
|
|
+ } as? NSKeyValueObservation
|
|
|
|
+
|
|
|
|
+ NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: avplayer.currentItem, queue: .main) { [weak avplayer] notify in
|
|
|
|
+ avplayer?.seek(to: CMTime.zero)
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return avplayer
|
|
|
|
+ }()
|
|
|
|
+
|
|
lazy var export : BFRecordExport = {
|
|
lazy var export : BFRecordExport = {
|
|
let export = BFRecordExport()
|
|
let export = BFRecordExport()
|
|
|
|
|
|
@@ -43,19 +72,21 @@ class INVideoExportController: BFBaseViewController {
|
|
}
|
|
}
|
|
|
|
|
|
if let fileUrl = url {
|
|
if let fileUrl = url {
|
|
- DispatchQueue.main.async {
|
|
|
|
|
|
+ DispatchQueue.main.async { [weak self] in
|
|
let item = AVPlayerItem(url: fileUrl)
|
|
let item = AVPlayerItem(url: fileUrl)
|
|
- let avplayer = AVPlayer(playerItem: item)
|
|
|
|
- let playerLayer = AVPlayerLayer(player: avplayer)
|
|
|
|
- playerLayer.frame = CGRect(x: 10, y: strongSelf.progressView.bottomY, width: cScreenWidth - 20, height: cScreenHeigth - strongSelf.progressView.bottomY - 10)
|
|
|
|
- strongSelf.view.layer.addSublayer(playerLayer)
|
|
|
|
- avplayer.play()
|
|
|
|
|
|
+ self?.avplayer.replaceCurrentItem(with: item)
|
|
|
|
+ self?.avplayer.play()
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return export
|
|
return export
|
|
}()
|
|
}()
|
|
|
|
|
|
|
|
+ deinit {
|
|
|
|
+ avplayerTimeObserver?.invalidate()
|
|
|
|
+ NotificationCenter.default.removeObserver(self)
|
|
|
|
+ }
|
|
|
|
+
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
override func viewWillAppear(_ animated: Bool) {
|
|
super.viewWillAppear(animated)
|
|
super.viewWillAppear(animated)
|
|
showNavigation()
|
|
showNavigation()
|
|
@@ -77,7 +108,30 @@ class INVideoExportController: BFBaseViewController {
|
|
view.addSubview(backV)
|
|
view.addSubview(backV)
|
|
view.addSubview(progressView)
|
|
view.addSubview(progressView)
|
|
view.addSubview(progressL)
|
|
view.addSubview(progressL)
|
|
|
|
+ view.addSubview(progreddL)
|
|
|
|
+ progreddL.snp.makeConstraints { make in
|
|
|
|
+ make.top.equalTo(progressView.snp.bottom).offset(10)
|
|
|
|
+ make.centerX.equalTo(progressL)
|
|
|
|
+ make.width.equalTo(100)
|
|
|
|
+ make.height.equalTo(20)
|
|
|
|
+ }
|
|
|
|
|
|
|
|
+ let playerLayer = AVPlayerLayer(player: avplayer)
|
|
|
|
+ playerLayer.frame = CGRect(x: 10, y: self.progressView.bottomY, width: cScreenWidth - 20, height: cScreenHeigth - self.progressView.bottomY - 10)
|
|
|
|
+ view.layer.addSublayer(playerLayer)
|
|
|
|
+
|
|
export.startExprot()
|
|
export.startExprot()
|
|
|
|
+
|
|
|
|
+ view.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(play)))
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ @objc func play(){
|
|
|
|
+ if self.avplayer.currentItem != nil {
|
|
|
|
+ if self.avplayer.timeControlStatus == .playing {
|
|
|
|
+ self.avplayer.pause()
|
|
|
|
+ }else if self.avplayer.timeControlStatus == .paused{
|
|
|
|
+ self.avplayer.play()
|
|
|
|
+ }
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|