|
@@ -15,20 +15,67 @@ class PublishNewVideoPhotoView: BaseView {
|
|
|
}
|
|
|
|
|
|
override func setupViews() {
|
|
|
- // 预览视图,必须设置
|
|
|
+ addSubview(recordButton)
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ override func setupLayouts() {
|
|
|
+ recordButton.snp.makeConstraints { (make) in
|
|
|
+ make.bottom.equalTo(-(kSafeTabBarHeight+48+20))
|
|
|
+ make.centerX.equalToSuperview()
|
|
|
+ make.size.equalTo(80)
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
override func setupData() {
|
|
|
- /// 开始预览
|
|
|
-// recorder?.startPreview()
|
|
|
- /// 开始预览前置/后置摄像头
|
|
|
-// recorder.startPreview(withPositon: AliyunIRecorderCameraPosition.back)
|
|
|
- /// 停止预览
|
|
|
-// recorder?.stopPreview()
|
|
|
+ //录制/拍摄
|
|
|
+ recordButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
+ // 开始录制/暂停录制
|
|
|
+ if PublishNewViewModel.shared.publishNewRecorderType == .video {
|
|
|
+ if (self?.recordButton.isSelected)! { //暂停拍摄
|
|
|
+ self?.stopTakeVideo()
|
|
|
+ }else { //开始拍摄
|
|
|
+ self?.startTakeVideo()
|
|
|
+ }
|
|
|
+ //切换按钮状态
|
|
|
+ self?.recordButton.isSelected = !(self?.recordButton.isSelected)!
|
|
|
+ }
|
|
|
+ // 拍照
|
|
|
+ if PublishNewViewModel.shared.publishNewRecorderType == .photo {
|
|
|
+ // 拍照
|
|
|
+ self?.takePhoto()
|
|
|
+ //切换按钮状态
|
|
|
+ self?.recordButton.isSelected = false
|
|
|
+ }
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ /// 开始拍视频
|
|
|
+ func startTakeVideo() {
|
|
|
+ recorder?.startRecording()
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 暂停拍视频
|
|
|
+ func stopTakeVideo() {
|
|
|
+ recorder?.stopRecording()
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 完成拍视频
|
|
|
+ func finishTakeVideo() {
|
|
|
+ recorder?.finishRecording()
|
|
|
+ }
|
|
|
+
|
|
|
+ /// 拍照
|
|
|
+ func takePhoto() {
|
|
|
+ recorder?.takePhoto({ (image, rawImage) in
|
|
|
+
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
// SDK录制类
|
|
|
lazy var recorder: AliyunIRecorder? = {
|
|
|
+
|
|
|
let recorder = AliyunIRecorder.init(delegate: self, videoSize: CGSize(width: 720, height: 1280))
|
|
|
// 预览View
|
|
|
recorder?.preview = self
|
|
@@ -36,38 +83,42 @@ class PublishNewVideoPhotoView: BaseView {
|
|
|
recorder?.beautifyStatus = true;
|
|
|
// 设置美颜度 [0,100]
|
|
|
recorder?.beautifyValue = 50
|
|
|
- // 后置摄像头采集分辨率 默认:AVCaptureSessionPreset1280x720
|
|
|
- recorder?.backCaptureSessionPreset = AVCaptureSession.Preset.hd1280x720.rawValue
|
|
|
// 前置摄像头采集分辨率 默认:AVCaptureSessionPreset1280x720
|
|
|
recorder?.frontCaptureSessionPreset = AVCaptureSession.Preset.hd1280x720.rawValue
|
|
|
+ // 后置摄像头采集分辨率 默认:AVCaptureSessionPreset1280x720
|
|
|
+ recorder?.backCaptureSessionPreset = AVCaptureSession.Preset.hd1280x720.rawValue
|
|
|
// 设置视频最大时长 默认8
|
|
|
recorder?.clipManager.maxDuration = 60
|
|
|
-
|
|
|
// 设置视频最小时长 默认8
|
|
|
- recorder?.clipManager.maxDuration = 3
|
|
|
-
|
|
|
-
|
|
|
- /*
|
|
|
- 视频的输出路径
|
|
|
- 注意:若上一次录制的 outputPath 路径的视频存在沙盒里没有删除,并且与本次录制的视频路径且相同重名的话,录制将会失败
|
|
|
- */
|
|
|
-// recorder?.outputPath = videoSavePath
|
|
|
-
|
|
|
- // 视频的输出类型
|
|
|
-// recorder?.outputType = AliyunIRecorderVideoOutputPixelFormatType.type420f
|
|
|
-
|
|
|
- /*
|
|
|
- 文件配置路径
|
|
|
- 注意:若上一次录制的 taskPath 路径的视频存在沙盒里没有删除,并且与本次录制的视频路径相且同重名的话,录制将会失败
|
|
|
- */
|
|
|
-// recorder?.taskPath = taskPath;
|
|
|
-
|
|
|
-
|
|
|
-
|
|
|
+ recorder?.clipManager.minDuration = 3
|
|
|
+ // 设置摄像头角度
|
|
|
+ recorder?.cameraRotate = 0
|
|
|
+ // 设置编码方式 0软编 1硬编
|
|
|
+ recorder?.encodeMode = 1
|
|
|
+ // 设置关键帧间隔
|
|
|
+ recorder?.gop = 5
|
|
|
+ // 设置关键帧间隔
|
|
|
+ recorder?.recordFps = 25
|
|
|
+ // 设置是否静音
|
|
|
+ recorder?.mute = false
|
|
|
+ // 设置视频质量 如果设置了bitrate参数,那么当前设置无效。
|
|
|
+ recorder?.videoQuality = .hight
|
|
|
+ // 设置输出视频码率(bps)
|
|
|
+ recorder?.bitrate = 2000000
|
|
|
+ // 设置采集视频格式
|
|
|
+ recorder?.outputType = .type420f
|
|
|
|
|
|
return recorder!
|
|
|
}()
|
|
|
|
|
|
+ /// 拍摄录制按钮
|
|
|
+ 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)
|
|
|
+ return recordButton
|
|
|
+ }()
|
|
|
+
|
|
|
// /// 显示授权View
|
|
|
// func showAuthorizationView() {
|
|
|
// PublishNewViewModel.shared.scrollView?.isHidden = true
|
|
@@ -95,6 +146,4 @@ extension PublishNewVideoPhotoView : AliyunIRecorderDelegate {
|
|
|
break
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
-
|
|
|
}
|