Browse Source

视频录制View

Chris 5 years ago
parent
commit
4a3423174b
18 changed files with 340 additions and 78 deletions
  1. 46 7
      RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishTakeVideo/PublishVideoRecorderController.swift
  2. 180 71
      RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishTakeVideo/PublishVideoView.swift
  3. 4 0
      RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishViewController.swift
  4. 22 0
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_close_white.imageset/Contents.json
  5. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_close_white.imageset/video_btn_close_white@2x.png
  6. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_close_white.imageset/video_btn_close_white@3x.png
  7. 22 0
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_delete.imageset/Contents.json
  8. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_delete.imageset/video_btn_delete@2x.png
  9. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_delete.imageset/video_btn_delete@3x.png
  10. 22 0
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_submit.imageset/Contents.json
  11. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_submit.imageset/video_btn_submit@2x.png
  12. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_submit.imageset/video_btn_submit@3x.png
  13. 22 0
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_filter.imageset/Contents.json
  14. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_filter.imageset/video_ico_filter@2x.png
  15. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_filter.imageset/video_ico_filter@3x.png
  16. 22 0
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_music.imageset/Contents.json
  17. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_music.imageset/video_ico_music@2x.png
  18. BIN
      RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_music.imageset/video_ico_music@3x.png

+ 46 - 7
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishTakeVideo/PublishVideoRecorderController.swift

@@ -12,6 +12,9 @@ import AliyunVideoSDKPro
 
 class PublishVideoRecorderController: BaseViewController {
     
+    typealias DismissClosure = () -> Void
+    var dismissClosure: DismissClosure?
+    
     override func viewDidLoad() {
         super.viewDidLoad()
         
@@ -19,14 +22,19 @@ class PublishVideoRecorderController: BaseViewController {
         setupLayouts()
     }
     
+    deinit {
+        // 控制器销毁时,销毁recorder
+        recorder.destroy()
+    }
+    
     override func setupViews() {
         navigationBar.isHidden = true
         
-        view.addSubview(tstView)
+        view.addSubview(videoCameraView)
     }
     
     override func setupLayouts() {
-        tstView.snp.makeConstraints { (make) in
+        videoCameraView.snp.makeConstraints { (make) in
             make.edges.equalToSuperview()
         }
     }
@@ -44,7 +52,7 @@ class PublishVideoRecorderController: BaseViewController {
         let recorder = AliyunIRecorder.init(delegate: self as? AliyunIRecorderDelegate, videoSize: CGSize(width: 720, height: 1280))
         
         // 预览视图,必须设置
-        recorder?.preview = tstView.previewView
+        recorder?.preview = videoCameraView.previewView
         
         // 摄像头角度
         recorder?.cameraRotate = 270;
@@ -82,10 +90,41 @@ class PublishVideoRecorderController: BaseViewController {
         return recorder!
     }()
     
-    lazy var tstView: PublishVideoView = {
-        let tstView = PublishVideoView()
-//        tstView.frame = CGRect(x: 0, y: 0, width: kScreenWidth, height: kScreenHeight)
-        return tstView
+    lazy var videoCameraView: PublishVideoView = {
+        let videoCameraView = PublishVideoView()
+        videoCameraView.btnClickClosure = {
+            [weak self] (btnType) in
+            switch btnType {
+            case .back:
+                if let dismissClosure = self?.dismissClosure {
+                    dismissClosure()
+                }
+                
+            case .reverse:
+                self?.recorder.switchCameraPosition()
+                
+            case .music:
+                print("----点击-music")
+                
+            case .filter:
+                print("----点击-filter")
+                
+            case .delete:
+                print("----点击-delete")
+                
+            case .confirm:
+                print("----点击-confirm")
+            }
+        }
+        videoCameraView.videoClosure = {
+            [weak self] (isRecording) in
+            if isRecording == 0 {
+                print("----暂停录制视频")
+            } else {
+                print("----开始录制视频")
+            }
+        }
+        return videoCameraView
     }()
     
     

+ 180 - 71
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishTakeVideo/PublishVideoView.swift

@@ -10,115 +10,224 @@ import UIKit
 import RxSwift
 import RxCocoa
 
+enum BtnActionType {
+    case back       // 返回
+    case reverse    // 翻转
+    case music      // 音乐
+    case filter     // 滤镜
+    case delete     // 回删
+    case confirm    // 确定
+}
+
 class PublishVideoView: BaseView {
     
-    typealias AllSelectBlock = (_ isAllSelected: Int) -> Void
-    var allSelectBlock : AllSelectBlock?
-    
-    typealias OrderPayBlock = () -> Void
-    var orderPayBlock : OrderPayBlock?
-    
-    var isAllSelected: Int? {
-        didSet {
-            // 选中状态
-            let selStatus = isAllSelected == 1 ? true : false
-            allSelectBtn.isSelected = selStatus
-        }
-    }
-    
+    typealias BtnClickClosure = (_ btnType: BtnActionType) -> Void
+    var btnClickClosure : BtnClickClosure?
     
+    typealias VideoClosure = (_ isRecording: Int) -> Void
+    var videoClosure : VideoClosure?
     
     override func setupViews() {
         self.backgroundColor = kffffffColor
-        addSubview(allSelectBtn)
-        addSubview(accountBtn)
-        addSubview(priceLabel)
-        addSubview(prePriceLabel)
-        addSubview(previewView)
         
+        addSubview(backButton)
+        addSubview(recordButton)
+        
+        addSubview(controlBackView)
+        controlBackView.addSubview(reverseButton)
+        controlBackView.addSubview(musicButton)
+        controlBackView.addSubview(filterButton)
+        
+        addSubview(selBackView)
+        selBackView.addSubview(confirmButton)
+        selBackView.addSubview(delButton)
+        
+        addSubview(previewView)
         insertSubview(previewView, at: 0)
     }
     
     override func setupLayouts() {
-        allSelectBtn.snp.makeConstraints { (make) in
-            make.left.equalToSuperview().offset(10)
-            make.centerY.equalToSuperview()
-            make.height.equalTo(30)
-            make.width.equalTo(54)
+        
+        backButton.snp.makeConstraints { (make) in
+            make.top.equalTo(55)
+            make.left.equalTo(5)
+            make.width.equalTo(40)
+            make.height.equalTo(40)
         }
-        allSelectBtn.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.left, imageTitleSpace: 4)
         
-        accountBtn.snp.makeConstraints { (make) in
-            make.right.equalToSuperview().offset(-14)
-            make.centerY.equalToSuperview()
+        recordButton.snp.makeConstraints { (make) in
+            make.bottom.equalTo(-56)
+            make.centerX.equalToSuperview()
             make.width.equalTo(100)
-            make.height.equalTo(37)
+            make.height.equalTo(100)
+        }
+        
+        /***** 翻转、音乐、滤镜 *****/
+        controlBackView.snp.makeConstraints { (make) in
+            make.top.equalTo(64)
+            make.right.equalTo(-15)
+            make.width.equalTo(44)
+        }
+        
+        reverseButton.snp.makeConstraints { (make) in
+            make.top.left.right.equalToSuperview()
+            make.height.equalTo(46)
+        }
+        reverseButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 4)
+        
+        musicButton.snp.makeConstraints { (make) in
+            make.top.equalTo(reverseButton.snp_bottom).offset(20)
+            make.left.right.equalToSuperview()
+            make.height.equalTo(46)
+        }
+        musicButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 4)
+        
+        filterButton.snp.makeConstraints { (make) in
+            make.top.equalTo(musicButton.snp_bottom).offset(20)
+            make.left.right.equalToSuperview()
+            make.height.equalTo(46)
+            make.bottom.equalToSuperview()
+        }
+        filterButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 4)
+        
+        /***** 回删、确定 *****/
+        selBackView.snp.makeConstraints { (make) in
+            make.bottom.equalTo(-83)
+            make.right.equalTo(-24*kScaleWidth)
+            make.height.equalTo(50)
         }
         
-        priceLabel.snp.makeConstraints { (make) in
-            make.centerY.equalToSuperview()
-            make.right.equalTo(accountBtn.snp_left).offset(-12)
-            make.height.equalTo(25)
+        confirmButton.snp.makeConstraints { (make) in
+            make.top.bottom.right.equalToSuperview()
+            make.width.equalTo(30)
         }
+        confirmButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 4)
         
-        prePriceLabel.snp.makeConstraints { (make) in
-            make.centerY.equalToSuperview()
-            make.right.equalTo(priceLabel.snp_left).offset(-1)
+        delButton.snp.makeConstraints { (make) in
+            make.right.equalTo(confirmButton.snp_left).offset(-30*kScaleWidth)
+            make.top.bottom.equalToSuperview()
+            make.width.equalTo(30)
+            make.left.equalToSuperview()
         }
+        delButton.layoutButton(edgeInsetsStyle: ButtonEdgeInsetsStyle.top, imageTitleSpace: 4)
         
+        /***** 预览视图 *****/
         previewView.snp.makeConstraints { (make) in
             make.edges.equalToSuperview()
         }
         
     }
     
-    private lazy var allSelectBtn: UIButton = {
-        let allSelectBtn = UIButton(type: UIButton.ButtonType.custom)
-        allSelectBtn.setTitle("全选", for: UIControl.State.normal)
-        allSelectBtn.setTitleColor(k333333Color, for: UIControl.State.normal)
-        allSelectBtn.setTitleColor(k666666Color, for: UIControl.State.selected)
-        allSelectBtn.setImage(kImage(name: "common_uncheck_icon"), for: UIControl.State.normal)
-        allSelectBtn.setImage(kImage(name: "common_check_icon"), for: UIControl.State.selected)
-        allSelectBtn.titleLabel?.font = kScaleRegularFont16
-        allSelectBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
-            allSelectBtn.isSelected = !allSelectBtn.isSelected
-            if let allSelectBlock = self?.allSelectBlock {
-                let isAllSel: Int = allSelectBtn.isSelected == true ? 1 : 0
-                allSelectBlock(isAllSel)
+    lazy var backButton: UIButton = {
+        let backButton = UIButton(type: UIButton.ButtonType.custom)
+        backButton.setImage(kImage(name: "video_btn_close_white"), for: UIControl.State.normal)
+        backButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            if let btnClickClosure = self?.btnClickClosure {
+                btnClickClosure(BtnActionType.back)
             }
         }).disposed(by: disposeBag)
-        return allSelectBtn
+        return backButton
     }()
     
-    private lazy var accountBtn: UIButton = {
-        let accountBtn = UIButton(type: UIButton.ButtonType.custom)
-        accountBtn.setTitle("结算(0)", for: UIControl.State.normal)
-        accountBtn.titleLabel?.font = kScaleRegularFont15
-        accountBtn.cornerRadius = 18
-        accountBtn.masksToBounds = true
-        accountBtn.rx.tap.subscribe(onNext: { [weak self] (data) in
-            if let orderPayBlock = self?.orderPayBlock {
-                orderPayBlock()
+    // 放置"翻转、音乐、滤镜"のView
+    lazy var controlBackView: UIView = {
+        let controlBackView = UIView()
+        return controlBackView
+    }()
+    
+    private lazy var reverseButton: UIButton = {
+        let reverseButton = UIButton(type: UIButton.ButtonType.custom)
+        reverseButton.setImage(kImage(name: "video_ico_overturn"), for: UIControl.State.normal)
+        reverseButton.setTitle("翻转", for: UIControl.State.normal)
+        reverseButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
+        reverseButton.titleLabel?.font = kRegularFont12
+        reverseButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            if let btnClickClosure = self?.btnClickClosure {
+                btnClickClosure(BtnActionType.reverse)
+            }
+        }).disposed(by: disposeBag)
+        return reverseButton
+    }()
+    
+    private lazy var musicButton: UIButton = {
+        let musicButton = UIButton(type: UIButton.ButtonType.custom)
+        musicButton.setImage(kImage(name: "video_ico_music"), for: UIControl.State.normal)
+        musicButton.setTitle("音乐", for: UIControl.State.normal)
+        musicButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
+        musicButton.titleLabel?.font = kRegularFont12
+        musicButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            if let btnClickClosure = self?.btnClickClosure {
+                btnClickClosure(BtnActionType.music)
+            }
+        }).disposed(by: disposeBag)
+        return musicButton
+    }()
+    
+    private lazy var filterButton: UIButton = {
+        let filterButton = UIButton(type: UIButton.ButtonType.custom)
+        filterButton.setImage(kImage(name: "video_ico_filter"), for: UIControl.State.normal)
+        filterButton.setTitle("滤镜", for: UIControl.State.normal)
+        filterButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
+        filterButton.titleLabel?.font = kRegularFont12
+        filterButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            if let btnClickClosure = self?.btnClickClosure {
+                btnClickClosure(BtnActionType.filter)
+            }
+        }).disposed(by: disposeBag)
+        return filterButton
+    }()
+    
+    // 放置"回删、确定"のView
+    lazy var selBackView: UIView = {
+        let selBackView = UIView()
+        return selBackView
+    }()
+    
+    private lazy var delButton: UIButton = {
+        let delButton = UIButton(type: UIButton.ButtonType.custom)
+        delButton.setImage(kImage(name: "video_btn_delete"), for: UIControl.State.normal)
+        delButton.setTitle("回删", for: UIControl.State.normal)
+        delButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
+        delButton.titleLabel?.font = kRegularFont12
+        delButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            if let btnClickClosure = self?.btnClickClosure {
+                btnClickClosure(BtnActionType.delete)
             }
         }).disposed(by: disposeBag)
-        return accountBtn
+        return delButton
     }()
     
-    private lazy var priceLabel: UILabel = {
-        let priceLabel = UILabel()
-        priceLabel.textColor = kFE352BColor
-        priceLabel.font = kScaleBoldFont18
-        return priceLabel
+    private lazy var confirmButton: UIButton = {
+        let confirmButton = UIButton(type: UIButton.ButtonType.custom)
+        confirmButton.setImage(kImage(name: "video_btn_submit"), for: UIControl.State.normal)
+        confirmButton.setTitle("确定", for: UIControl.State.normal)
+        confirmButton.setTitleColor(kffffffColor, for: UIControl.State.normal)
+        confirmButton.titleLabel?.font = kRegularFont12
+        confirmButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            if let btnClickClosure = self?.btnClickClosure {
+                btnClickClosure(BtnActionType.confirm)
+            }
+        }).disposed(by: disposeBag)
+        return confirmButton
     }()
     
-    private lazy var prePriceLabel: UILabel = {
-        let prePriceLabel = UILabel()
-        prePriceLabel.text = "合计"
-        prePriceLabel.textColor = k333333Color
-        prePriceLabel.font = kScaleRegularFont16
-        return prePriceLabel
+    // 录制のButton
+    private lazy var recordButton: UIButton = {
+        let recordButton = UIButton(type: UIButton.ButtonType.custom)
+        recordButton.setImage(kImage(name: "video_btn_shoot"), for: UIControl.State.normal)
+        recordButton.setImage(kImage(name: "video_btn_pause"), for: UIControl.State.selected)
+        recordButton.rx.tap.subscribe(onNext: { [weak self] (data) in
+            recordButton.isSelected = !recordButton.isSelected
+            if let videoClosure = self?.videoClosure {
+                let isRecording: Int = recordButton.isSelected == true ? 1 : 0
+                videoClosure(isRecording)
+            }
+        }).disposed(by: disposeBag)
+        
+        return recordButton
     }()
     
+    
     // 预览View
     lazy var previewView: UIView = {
         let previewView = UIView()

+ 4 - 0
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishViewController.swift

@@ -170,6 +170,10 @@ extension PublishViewController :JXSegmentedListContainerViewDataSource {
             return mediaVc
         case 1:
             let videoVc = PublishVideoRecorderController()
+            videoVc.dismissClosure = {
+                [weak self] in
+                self?.dismiss(animated: true, completion: nil)
+            }
             return videoVc        
         default:
             let photoVc = PublishTakePhotoController()

+ 22 - 0
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_close_white.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_btn_close_white@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_btn_close_white@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_close_white.imageset/video_btn_close_white@2x.png


BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_close_white.imageset/video_btn_close_white@3x.png


+ 22 - 0
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_delete.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_btn_delete@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_btn_delete@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_delete.imageset/video_btn_delete@2x.png


BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_delete.imageset/video_btn_delete@3x.png


+ 22 - 0
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_submit.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_btn_submit@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_btn_submit@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_submit.imageset/video_btn_submit@2x.png


BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_btn_submit.imageset/video_btn_submit@3x.png


+ 22 - 0
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_filter.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_ico_filter@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_ico_filter@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_filter.imageset/video_ico_filter@2x.png


BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_filter.imageset/video_ico_filter@3x.png


+ 22 - 0
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_music.imageset/Contents.json

@@ -0,0 +1,22 @@
+{
+  "images" : [
+    {
+      "idiom" : "universal",
+      "scale" : "1x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_ico_music@2x.png",
+      "scale" : "2x"
+    },
+    {
+      "idiom" : "universal",
+      "filename" : "video_ico_music@3x.png",
+      "scale" : "3x"
+    }
+  ],
+  "info" : {
+    "version" : 1,
+    "author" : "xcode"
+  }
+}

BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_music.imageset/video_ico_music@2x.png


BIN
RainbowPlanet/RainbowPlanet/Supporting Files/PublishModule.xcassets/video_ico_music.imageset/video_ico_music@3x.png