|
@@ -11,6 +11,7 @@ import BFRecordScreenKit
|
|
|
import BFUIKit
|
|
|
import Foundation
|
|
|
import Photos
|
|
|
+import SwiftUI
|
|
|
import UIKit
|
|
|
|
|
|
class INVideoExportController: BFBaseViewController {
|
|
@@ -22,6 +23,7 @@ class INVideoExportController: BFBaseViewController {
|
|
|
var hasSaveOnly = false
|
|
|
var saveAllUlr = URL(fileURLWithPath: "aaa")
|
|
|
var saveOnlyUlr = URL(fileURLWithPath: "aaa")
|
|
|
+ var playViewFrame: CGRect = CGRect.zero
|
|
|
var isExporting = false {
|
|
|
didSet {
|
|
|
if isExporting {
|
|
@@ -95,6 +97,7 @@ class INVideoExportController: BFBaseViewController {
|
|
|
return vv
|
|
|
}()
|
|
|
|
|
|
+ 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
|
|
@@ -106,9 +109,12 @@ class INVideoExportController: BFBaseViewController {
|
|
|
}
|
|
|
} as? NSKeyValueObservation
|
|
|
|
|
|
- NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: avplayer.currentItem, queue: .main) { [weak avplayer,weak self] _ in
|
|
|
+ NotificationCenter.default.addObserver(forName: .AVPlayerItemDidPlayToEndTime, object: avplayer.currentItem, queue: .main) { [weak avplayer, weak self] _ in
|
|
|
avplayer?.seek(to: CMTime.zero)
|
|
|
self?.sliderView?.playEnd()
|
|
|
+ if self?.sliderView?.isFullScreen ?? false {
|
|
|
+ self?.changeToOriginalFrame()
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
return avplayer
|
|
@@ -208,7 +214,7 @@ class INVideoExportController: BFBaseViewController {
|
|
|
leftButton(image: nil, imageName: nil, tintColor: UIColor.white)
|
|
|
|
|
|
// backV.frame = CGRect(x: 0, y: navHeadImageView?.bottomY ?? 0, width: cScreenWidth, height: cScreenWidth)
|
|
|
- backV.backgroundColor = .clear
|
|
|
+ backV.backgroundColor = .black
|
|
|
// backV.addGestureRecognizer(UITapGestureRecognizer(target: self, action: #selector(play)))
|
|
|
|
|
|
addSubviews()
|
|
@@ -221,10 +227,10 @@ class INVideoExportController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
func addSubviews() {
|
|
|
- view.addSubview(backV)
|
|
|
view.addSubview(bottomView)
|
|
|
+ view.addSubview(backV)
|
|
|
|
|
|
- let playerLayer = AVPlayerLayer(player: avplayer)
|
|
|
+ playerLayer = AVPlayerLayer(player: avplayer)
|
|
|
backV.layer.addSublayer(playerLayer)
|
|
|
|
|
|
backV.addSubview(progressView)
|
|
@@ -235,12 +241,6 @@ class INVideoExportController: BFBaseViewController {
|
|
|
bottomView.addSubview(saveToPhotoBtn)
|
|
|
bottomView.addSubview(completeBtn)
|
|
|
|
|
|
- backV.snp.makeConstraints { make in
|
|
|
- make.left.right.equalToSuperview()
|
|
|
- make.top.equalTo(navHeadImageView!.snp.bottom)
|
|
|
- make.bottom.equalTo(bottomView.snp.top)
|
|
|
- }
|
|
|
-
|
|
|
progressView.snp.makeConstraints { make in
|
|
|
make.left.top.height.equalToSuperview()
|
|
|
make.width.equalTo(0)
|
|
@@ -287,7 +287,8 @@ class INVideoExportController: BFBaseViewController {
|
|
|
}
|
|
|
|
|
|
DispatchQueue.main.asyncAfter(deadline: .now() + 0) { [weak self] in
|
|
|
- playerLayer.frame = self!.backV.bounds
|
|
|
+ self?.backV.frame = CGRect(x: 0, y: self?.navHeadImageView?.frame.maxY ?? 0, width: self?.view.width ?? 0, height: (self?.bottomView.frame.minY ?? 0) - (self?.navHeadImageView?.frame.maxY ?? 0))
|
|
|
+ self?.playerLayer.frame = self!.backV.bounds
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -304,6 +305,12 @@ class INVideoExportController: BFBaseViewController {
|
|
|
// 按钮点击
|
|
|
if sender.tag == 1 {
|
|
|
self?.play(sender: sender)
|
|
|
+ } else if sender.tag == 2 {
|
|
|
+ if sender.isSelected {
|
|
|
+ self?.changeToFullScreen()
|
|
|
+ } else {
|
|
|
+ self?.changeToOriginalFrame()
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
@@ -472,3 +479,58 @@ class INVideoExportController: BFBaseViewController {
|
|
|
UIApplication.shared.keyWindow?.addSubview(alertV)
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+extension INVideoExportController {
|
|
|
+ @objc func changeToOriginalFrame() {
|
|
|
+ if !(sliderView?.isFullScreen ?? false) {
|
|
|
+ isHiddenStatus = false // (0.0, 64.0, 375.0, 401.0)
|
|
|
+ navHeadImageView?.isHidden = false
|
|
|
+ backV.frame = CGRect(x: 0, y: navHeadImageView?.frame.maxY ?? 0, width: view.width, height: bottomView.frame.minY - (navHeadImageView?.frame.maxY ?? 0))
|
|
|
+ playerLayer.frame = CGRect(x: 0, y: 0, width: view.width, height: bottomView.frame.minY - (navHeadImageView?.frame.maxY ?? 0))
|
|
|
+ sliderView?.frame = CGRect(x: 0, y: backV.frame.height - 60, width: view.frame.width, height: 50)
|
|
|
+ UIView.animate(withDuration: 0.2, animations: { [weak self] in
|
|
|
+ self?.changeOrientation(orientation: .portrait)
|
|
|
+ self?.backV.center = CGPoint(x: (self?.backV.width ?? 0) / 2, y: (self?.backV.height ?? 0) / 2 + (self?.navHeadImageView?.frame.maxY ?? 0))
|
|
|
+ }) { [weak self] _ in
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func changeToFullScreen() {
|
|
|
+ if sliderView?.isFullScreen ?? false {
|
|
|
+ isHiddenStatus = true
|
|
|
+ navHeadImageView?.isHidden = true
|
|
|
+ backV.frame = CGRect(x: 0, y: 0, width: view.frame.height, height: view.frame.width)
|
|
|
+ playerLayer.frame = backV.bounds
|
|
|
+ sliderView?.frame = CGRect(x: 0, y: backV.frame.height - 60, width: backV.frame.width, height: 50)
|
|
|
+ UIView.animate(withDuration: 0.2, animations: { [weak self] in
|
|
|
+ let orientation = UIDevice.current.orientation
|
|
|
+ if orientation == .landscapeRight {
|
|
|
+ self?.changeOrientation(orientation: .landscapeLeft)
|
|
|
+ } else {
|
|
|
+ self?.changeOrientation(orientation: .landscapeRight)
|
|
|
+ }
|
|
|
+ self?.backV.center = CGPoint(x: (self?.view.frame.width ?? 0) / 2, y: (self?.view.frame.height ?? 0) / 2)
|
|
|
+ }) { [weak self] _ in
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ func changeOrientation(orientation: UIInterfaceOrientation) {
|
|
|
+ UIView.animate(withDuration: 0.2, animations: { [weak self] in
|
|
|
+ self?.backV.transform = self?.transformRotation(orientation: orientation) as! CGAffineTransform
|
|
|
+ }) { [weak self] _ in
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @objc func transformRotation(orientation: UIInterfaceOrientation) -> CGAffineTransform {
|
|
|
+ if orientation == .portrait {
|
|
|
+ return .identity
|
|
|
+ } else if orientation == .landscapeLeft {
|
|
|
+ return CGAffineTransform(rotationAngle: -CGFloat.pi / 2)
|
|
|
+ } else if orientation == .landscapeRight {
|
|
|
+ return CGAffineTransform(rotationAngle: CGFloat.pi / 2)
|
|
|
+ }
|
|
|
+ return .identity
|
|
|
+ }
|
|
|
+}
|