Quellcode durchsuchen

编辑预览图出来了

南鑫林 vor 5 Jahren
Ursprung
Commit
3cd3edbb09

+ 16 - 0
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -191,6 +191,8 @@
 		A747D848235DA16F007F4E33 /* CircleAlbumSectionFooterCollectionReusableView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A747D847235DA16F007F4E33 /* CircleAlbumSectionFooterCollectionReusableView.swift */; };
 		A74CF41D23715A9500BA620E /* Extension+DispatchQueue.swift in Sources */ = {isa = PBXBuildFile; fileRef = A74CF41C23715A9500BA620E /* Extension+DispatchQueue.swift */; };
 		A74CF4272372DB2400BA620E /* PublishEditNewViewController.swift in Sources */ = {isa = PBXBuildFile; fileRef = A74CF4262372DB2400BA620E /* PublishEditNewViewController.swift */; };
+		A74CF42A237313BA00BA620E /* PublishEditNewVideoView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A74CF429237313BA00BA620E /* PublishEditNewVideoView.swift */; };
+		A74CF42C237318B200BA620E /* PublishEditNewVideoPreView.swift in Sources */ = {isa = PBXBuildFile; fileRef = A74CF42B237318B200BA620E /* PublishEditNewVideoPreView.swift */; };
 		A74D9D572327B54100F05C14 /* NotificationService.swift in Sources */ = {isa = PBXBuildFile; fileRef = A74D9D562327B54100F05C14 /* NotificationService.swift */; };
 		A74D9D5B2327B54100F05C14 /* NotificationService.appex in Embed App Extensions */ = {isa = PBXBuildFile; fileRef = A74D9D542327B54100F05C14 /* NotificationService.appex */; settings = {ATTRIBUTES = (RemoveHeadersOnCopy, ); }; };
 		A74DF74922EAAF17007FB505 /* MJDIYFullScreenHeader.swift in Sources */ = {isa = PBXBuildFile; fileRef = A74DF74822EAAF17007FB505 /* MJDIYFullScreenHeader.swift */; };
@@ -935,6 +937,8 @@
 		A747D847235DA16F007F4E33 /* CircleAlbumSectionFooterCollectionReusableView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CircleAlbumSectionFooterCollectionReusableView.swift; sourceTree = "<group>"; };
 		A74CF41C23715A9500BA620E /* Extension+DispatchQueue.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Extension+DispatchQueue.swift"; sourceTree = "<group>"; };
 		A74CF4262372DB2400BA620E /* PublishEditNewViewController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishEditNewViewController.swift; sourceTree = "<group>"; };
+		A74CF429237313BA00BA620E /* PublishEditNewVideoView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishEditNewVideoView.swift; sourceTree = "<group>"; };
+		A74CF42B237318B200BA620E /* PublishEditNewVideoPreView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = PublishEditNewVideoPreView.swift; sourceTree = "<group>"; };
 		A74D9D542327B54100F05C14 /* NotificationService.appex */ = {isa = PBXFileReference; explicitFileType = "wrapper.app-extension"; includeInIndex = 0; path = NotificationService.appex; sourceTree = BUILT_PRODUCTS_DIR; };
 		A74D9D562327B54100F05C14 /* NotificationService.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NotificationService.swift; sourceTree = "<group>"; };
 		A74D9D582327B54100F05C14 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
@@ -2658,6 +2662,7 @@
 		A74CF4242372CD9100BA620E /* PublishEditNew */ = {
 			isa = PBXGroup;
 			children = (
+				A74CF4282373136100BA620E /* View */,
 				A74CF4252372D7CE00BA620E /* ViewController */,
 			);
 			path = PublishEditNew;
@@ -2671,6 +2676,15 @@
 			path = ViewController;
 			sourceTree = "<group>";
 		};
+		A74CF4282373136100BA620E /* View */ = {
+			isa = PBXGroup;
+			children = (
+				A74CF429237313BA00BA620E /* PublishEditNewVideoView.swift */,
+				A74CF42B237318B200BA620E /* PublishEditNewVideoPreView.swift */,
+			);
+			path = View;
+			sourceTree = "<group>";
+		};
 		A74D9D552327B54100F05C14 /* NotificationService */ = {
 			isa = PBXGroup;
 			children = (
@@ -6291,6 +6305,7 @@
 				BD01B20122BC677900CE9F36 /* PublishFilterView.swift in Sources */,
 				BD5CA89522DDA2A100364A67 /* CustomSlider.swift in Sources */,
 				A7811C85231AB2F600C2D8DE /* CommunityReportHeaderView.swift in Sources */,
+				A74CF42A237313BA00BA620E /* PublishEditNewVideoView.swift in Sources */,
 				A75B782522DEC592007B986A /* SpecialOneTypeCollectionViewCell.swift in Sources */,
 				A76068F522E4BCF4008DF18F /* MJDIYHeader.swift in Sources */,
 				A77F2CCA223209F2001BD3F6 /* BaseTabbarViewController.swift in Sources */,
@@ -6389,6 +6404,7 @@
 				BD0FAA5322C4750A00DDFB37 /* AliyunCoverPickView.m in Sources */,
 				A790706122B9C294008CE279 /* ModifyDataNickNameSignView.swift in Sources */,
 				BD12204622AF997E0051C7C2 /* MessageListTableCell.swift in Sources */,
+				A74CF42C237318B200BA620E /* PublishEditNewVideoPreView.swift in Sources */,
 				A74322AB22B900F00017C367 /* CommunityFindFriendsView.swift in Sources */,
 				A71AF0B6226EF99A001730FE /* SearchResultViewController.swift in Sources */,
 				A7F3069722E1AE9600DC7917 /* MessageModuleManager.swift in Sources */,

+ 109 - 0
RainbowPlanet/RainbowPlanet/Modules/PublishNewModule/PublishEditNew/View/PublishEditNewVideoPreView.swift

@@ -0,0 +1,109 @@
+//
+//  PublishEditNewVideoPreView.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/11/6.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+
+class PublishEditNewVideoPreView: BaseView {
+    
+    override func setupViews() {
+        // 滤镜名字
+        addSubview(filterNameLabel)
+        // 左滑手势
+        addLeftSwipe()
+        // 右滑手势
+        addRightSwipe()
+    }
+    
+    override func setupLayouts() {
+        // 滤镜名字
+        filterNameLabel.snp.makeConstraints { (make) in
+            make.top.equalTo(kNavBarTotalHeight + 20)
+            make.centerX.equalToSuperview()
+        }
+    }
+    
+    /// 滤镜名字
+    lazy var filterNameLabel: UILabel = {
+        let filterNameLabel = UILabel()
+        filterNameLabel.alpha = 0
+        filterNameLabel.font = kMediumFont20
+        filterNameLabel.textColor = kffffffColor
+        return filterNameLabel
+    }()
+
+    lazy var tap: UITapGestureRecognizer = {
+        let tap = UITapGestureRecognizer(target: self, action: #selector(tapAction))
+        tap.numberOfTapsRequired = 1
+        tap.numberOfTouchesRequired = 1
+        return tap
+    }()
+    
+    lazy var leftSwipe: UISwipeGestureRecognizer = {
+        let leftSwipe = UISwipeGestureRecognizer(target: self, action: #selector(leftSwipeAction))
+        leftSwipe.direction = .left
+        return leftSwipe
+    }()
+    
+    lazy var rightSwipe: UISwipeGestureRecognizer = {
+        let rightSwipe = UISwipeGestureRecognizer(target: self, action: #selector(rightSwipeAction))
+        rightSwipe.direction = .right
+        return rightSwipe
+    }()
+    
+   
+    /// 添加轻点手势
+    func addTap() {
+        addGestureRecognizer(tap)
+    }
+    
+    
+    
+    /// 移除手势
+    func removetap() {
+        removeGestureRecognizer(tap)
+    }
+    
+    /// 点击手势
+    typealias TapClosure = () -> Void
+    var tapClosure : TapClosure?
+    @objc func tapAction() {
+        if let tapClosure = tapClosure {
+            tapClosure()
+        }
+    }
+    
+    
+    /// 添加左滑手势
+    func addLeftSwipe() {
+        addGestureRecognizer(leftSwipe)
+    }
+    
+    /// 添加有滑动滑手势
+    func addRightSwipe() {
+        addGestureRecognizer(rightSwipe)
+    }
+    
+    /// 左滑手势
+    typealias LeftSwipeClosure = () -> Void
+    var leftSwipeClosure : LeftSwipeClosure?
+    @objc func leftSwipeAction() {
+        if let leftSwipeClosure = leftSwipeClosure {
+            leftSwipeClosure()
+        }
+    }
+    
+    /// 右滑手势
+    typealias RightSwipeClosure = () -> Void
+    var rightSwipeClosure : RightSwipeClosure?
+    @objc func rightSwipeAction() {
+        if let rightSwipeClosure = rightSwipeClosure {
+            rightSwipeClosure()
+        }
+    }
+    
+}

+ 147 - 0
RainbowPlanet/RainbowPlanet/Modules/PublishNewModule/PublishEditNew/View/PublishEditNewVideoView.swift

@@ -0,0 +1,147 @@
+//
+//  PublishEditNewVideoView.swift
+//  RainbowPlanet
+//
+//  Created by 南鑫林 on 2019/11/6.
+//  Copyright © 2019 RainbowPlanet. All rights reserved.
+//
+
+import UIKit
+
+class PublishEditNewVideoView: UIView {
+
+    /// 销毁View
+    deinit {
+        NXLLog("deinit")
+        editor?.stopEdit()
+        if observe != nil {
+            NotificationCenter.default.removeObserver(observe!)
+        }
+    }
+    weak var observe : NSObjectProtocol?
+    var taskPath : String?
+    
+    override init(frame: CGRect) {
+        super.init(frame: frame)
+    }
+    
+    required init?(coder aDecoder: NSCoder) {
+        fatalError("init(coder:) has not been implemented")
+    }
+    
+    init(taskPath:String?) {
+        self.init()
+        frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight)
+        self.taskPath = taskPath
+        setupViews()
+        setupLayouts()
+        setupData()
+    }
+    
+    /// 添加View
+    func setupViews() {
+        backgroundColor = UIColor.black
+        addSubview(editorPreview)
+    }
+    
+    /// 布局
+    func setupLayouts() {
+
+    }
+    
+    /// 设置数据
+    func setupData() {
+        //播放器视频
+        player?.play()
+        
+    }
+    
+    // 编辑
+    lazy var editor: AliyunEditor? = {
+        let editor = AliyunEditor(path: taskPath, preview: editorPreview)
+        editor?.delegate = self
+        editor?.startEdit()
+        if PublishNewMusicView.publishNewMusicUseURL != nil {
+            editor?.apply(AliyunEffectMusic(file: PublishNewMusicView.publishNewMusicUseURL?.path))
+        }
+        return editor
+    }()
+    
+    // 编辑预览view
+    lazy var editorPreview : PublishEditNewVideoPreView = {
+        let editorPreview = PublishEditNewVideoPreView(frame: kScreenBounds)
+        return editorPreview
+    }()
+    
+    // 获取播放器
+    lazy var player: AliyunIPlayer? = {
+        let player = editor?.getPlayer()
+        return player
+    }()
+    
+    // 媒体片段管理
+    lazy var clip: AliyunIClipConstructor? = {
+        let clip = editor?.getClipConstructor()
+        return clip
+    }()
+    
+    // 合成导出
+    lazy var exporter: AliyunIExporter? = {
+        let exporter = editor?.getExporter()
+        return exporter
+    }()
+
+}
+
+extension PublishEditNewVideoView : AliyunIExporterCallback {
+    func exporterDidEnd(_ outputPath: String!) {
+        
+    }
+    
+    func exporterDidCancel() {
+        
+    }
+    
+    func exportProgress(_ progress: Float) {
+        
+    }
+    
+    func exportError(_ errorCode: Int32) {
+        
+    }
+    
+    func exporterDidStart() {
+        
+    }
+    
+    
+}
+
+extension PublishEditNewVideoView : AliyunIPlayerCallback {
+    
+    func playerDidEnd() {
+        _ = player?.replay()
+    }
+    
+    func playProgress(_ playSec: Double, streamProgress streamSec: Double) {
+        
+    }
+    
+    func playError(_ errorCode: Int32) {
+        
+    }
+    
+    func seekDidEnd() {
+        
+    }
+    
+    func playerDidStart() {
+        
+    }
+    
+    
+}
+
+extension PublishEditNewVideoView : AliyunIRenderCallback {
+    
+}

+ 30 - 13
RainbowPlanet/RainbowPlanet/Modules/PublishNewModule/PublishEditNew/ViewController/PublishEditNewViewController.swift

@@ -9,22 +9,39 @@
 import UIKit
 
 class PublishEditNewViewController: BaseViewController {
-
+    
+    
+    
+    deinit {
+        NXLLog("deinit")
+    }
+    
+    var taskPath : String?
+    
     override func viewDidLoad() {
         super.viewDidLoad()
-
-        // Do any additional setup after loading the view.
+        setupViews()
     }
     
-
-    /*
-    // MARK: - Navigation
-
-    // In a storyboard-based application, you will often want to do a little preparation before navigation
-    override func prepare(for segue: UIStoryboardSegue, sender: Any?) {
-        // Get the new view controller using segue.destination.
-        // Pass the selected object to the new view controller.
+    override func setupViews() {
+        self.statusBarStyle = .lightContent
+        view.addSubview(publishEditNewVideoView)
+    }
+    
+    /// 编辑视频View
+    private lazy var publishEditNewVideoView: PublishEditNewVideoView = {
+        let publishEditNewVideoView = PublishEditNewVideoView(taskPath: taskPath)
+        return publishEditNewVideoView
+    }()
+    
+    typealias POPClosure = () -> Void
+    var popClosure : POPClosure?
+    
+    override func didMove(toParent parent: UIViewController?) {
+        if !(parent != nil) {
+            if let popClosure = popClosure {
+                popClosure()
+            }
+        }
     }
-    */
-
 }

+ 23 - 0
RainbowPlanet/RainbowPlanet/Modules/PublishNewModule/PublishNew/View/PublishNewView/PublishNewVideoPhotoView.swift

@@ -14,7 +14,11 @@ class PublishNewVideoPhotoView: BaseView {
     /// 销毁View
     deinit {
         NXLLog("deinit")
+        if observe != nil {
+            NotificationCenter.default.removeObserver(observe!)
+        }
     }
+    weak var observe : NSObjectProtocol?
     
     /// 录制的时长
     var recorderDuration: CGFloat = 0.0
@@ -203,6 +207,19 @@ class PublishNewVideoPhotoView: BaseView {
             }
         }
         
+        // 对于锁屏,来电,退后台等事件,需要进行特殊处理。
+        //当进入Inactive状态前需要调
+        observe = NotificationCenter.default.addObserver(forName: UIApplication.willResignActiveNotification, object: nil, queue: OperationQueue.main) {[weak self] (_) in
+            if self?.recorder?.isRecording ?? true {
+                self?.stopTakeVideo()
+            }
+            self?.recorder?.stopPreview()
+        }
+        // 当进入Active状态
+        observe = NotificationCenter.default.addObserver(forName: UIApplication.didBecomeActiveNotification, object: nil, queue: OperationQueue.main) {[weak self] (_) in
+            self?.recorder?.stopPreview()
+        }
+        
     }
     
     /// SDK录制类
@@ -292,6 +309,7 @@ class PublishNewVideoPhotoView: BaseView {
         return musicView
     }()
     
+    
 }
 
 
@@ -786,6 +804,11 @@ extension PublishNewVideoPhotoView : AliyunIRecorderDelegate {
             [weak self] in
             self?.publishNewVideoPhotoSetView.recordButton.isSelected = false
             let vc = PublishEditNewViewController()
+            vc.taskPath = self?.recorder?.taskPath
+            vc.popClosure = {
+                [weak self] in
+                self?.recorder?.startPreview()
+            }
             UIViewController.topMost?.navigationController?.pushViewController(vc, animated: true)
         }