|
@@ -25,13 +25,16 @@ class PublishNewVideoPhotoView: BaseView {
|
|
|
|
|
|
let minDuration : CGFloat = 3.0
|
|
|
|
|
|
+
|
|
|
+ var selectedIndex : Int = 0
|
|
|
+
|
|
|
|
|
|
override func setupViews() {
|
|
|
backgroundColor = UIColor.black
|
|
|
addSubview(recorderPreview)
|
|
|
addSubview(publishNewVideoPhotoSetView)
|
|
|
addSubview(effectFilterBeautyView)
|
|
|
-
|
|
|
+ addSubview(musicView)
|
|
|
}
|
|
|
|
|
|
|
|
@@ -50,24 +53,38 @@ class PublishNewVideoPhotoView: BaseView {
|
|
|
let vc = UIViewController.topMost
|
|
|
vc?.navigationController?.dismiss(animated: true, completion: nil)
|
|
|
}).disposed(by: disposeBag)
|
|
|
-
|
|
|
|
|
|
publishNewVideoPhotoSetView.cameraFlipButton.rx.tap.subscribe(onNext: {[weak self] (data) in
|
|
|
self?.setCameraFlip()
|
|
|
}).disposed(by: disposeBag)
|
|
|
-
|
|
|
|
|
|
publishNewVideoPhotoSetView.filterButton.rx.tap.subscribe(onNext: {[weak self] (data) in
|
|
|
self?.effectFilterBeautyView.filterBeautyType = .filter
|
|
|
self?.effectFilterBeautyViewisHidden(isHidden: false)
|
|
|
}).disposed(by: disposeBag)
|
|
|
-
|
|
|
|
|
|
publishNewVideoPhotoSetView.beautyButton.rx.tap.subscribe(onNext: {[weak self] (data) in
|
|
|
self?.effectFilterBeautyView.filterBeautyType = .beauty
|
|
|
self?.effectFilterBeautyViewisHidden(isHidden: false)
|
|
|
}).disposed(by: disposeBag)
|
|
|
-
|
|
|
+
|
|
|
+ publishNewVideoPhotoSetView.musicButton.rx.tap.subscribe(onNext: {[weak self] (data) in
|
|
|
+ self?.musicViewisHidden(isHidden: false)
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+
|
|
|
+ publishNewVideoPhotoSetView.flashButton.rx.tap.subscribe(onNext: {[weak self] (data) in
|
|
|
+ if self?.recorder?.torchMode == .auto {
|
|
|
+ self?.recorder?.switchTorch(with: AliyunIRecorderTorchMode.on)
|
|
|
+ self?.publishNewVideoPhotoSetView.flashButton.setImage(kImage(name: "video_ico_flashlight"), for: UIControl.State.normal)
|
|
|
+ } else if self?.recorder?.torchMode == .on {
|
|
|
+ self?.recorder?.switchTorch(with: AliyunIRecorderTorchMode.off)
|
|
|
+ self?.publishNewVideoPhotoSetView.flashButton.setImage(kImage(name: "video_ico_flashlight_close"), for: UIControl.State.normal)
|
|
|
+ } else if self?.recorder?.torchMode == .off {
|
|
|
+ self?.recorder?.switchTorch(with: AliyunIRecorderTorchMode.auto)
|
|
|
+ self?.publishNewVideoPhotoSetView.flashButton.setImage(kImage(name: "video_ico_flashlight_auto"), for: UIControl.State.normal)
|
|
|
+ }
|
|
|
+
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
|
|
|
publishNewVideoPhotoSetView.recordButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
|
|
@@ -88,44 +105,123 @@ class PublishNewVideoPhotoView: BaseView {
|
|
|
self?.publishNewVideoPhotoSetView.recordButton.isSelected = false
|
|
|
}
|
|
|
}).disposed(by: disposeBag)
|
|
|
-
|
|
|
|
|
|
publishNewVideoPhotoSetView.deleteButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
|
|
|
self?.deleteVideo()
|
|
|
}).disposed(by: disposeBag)
|
|
|
-
|
|
|
|
|
|
publishNewVideoPhotoSetView.finishButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
|
|
|
self?.finishTakeVideo()
|
|
|
}).disposed(by: disposeBag)
|
|
|
-
|
|
|
-
|
|
|
- recorderPreview.tapClosure = {
|
|
|
+
|
|
|
+ publishNewVideoPhotoSetView.leftSwipeClosure = {
|
|
|
+ [weak self] in
|
|
|
+ self?.filterPlus()
|
|
|
+ }
|
|
|
+
|
|
|
+ publishNewVideoPhotoSetView.rightSwipeClosure = {
|
|
|
[weak self] in
|
|
|
-
|
|
|
- self?.effectFilterBeautyViewisHidden(isHidden: true)
|
|
|
+ self?.filterLess()
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
|
|
|
effectFilterBeautyView.effectBeautyView.didSelectCloSure = {
|
|
|
[weak self] beautifyValue in
|
|
|
self?.recorder?.beautifyValue = beautifyValue
|
|
|
}
|
|
|
+
|
|
|
+ effectFilterBeautyView.effectFilterView.didSelectCloSure = {
|
|
|
+ [weak self] (index, aliyunEffectFilter) in
|
|
|
+ self?.selectedIndex = index
|
|
|
+ if index == 0 {
|
|
|
+ self?.recorder?.deleteFilter()
|
|
|
+ }else {
|
|
|
+ self?.recorder?.apply(aliyunEffectFilter)
|
|
|
+ }
|
|
|
+ self?.showFilterNameLabel(aliyunEffectFilter: aliyunEffectFilter)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ musicView.closeButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
+ AliPlayerManager.shared.audioPlayer.stop()
|
|
|
+ self?.musicViewisHidden(isHidden: true)
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+
|
|
|
+
|
|
|
+ musicView.noUseMusicButton.rx.tap.subscribe(onNext: { [weak self] (data) in
|
|
|
+ self?.recorder?.apply(AliyunEffectMusic())
|
|
|
+ AliPlayerManager.shared.audioPlayer.stop()
|
|
|
+ self?.musicViewisHidden(isHidden: true)
|
|
|
+ }).disposed(by: disposeBag)
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ recorderPreview.leftSwipeClosure = {
|
|
|
+ [weak self] in
|
|
|
+ self?.filterPlus()
|
|
|
+ }
|
|
|
+
|
|
|
+ recorderPreview.rightSwipeClosure = {
|
|
|
+ [weak self] in
|
|
|
+ self?.filterLess()
|
|
|
+ }
|
|
|
+
|
|
|
+ recorderPreview.tapClosure = {
|
|
|
+ [weak self] in
|
|
|
+ if self?.effectFilterBeautyView.alpha == 1 {
|
|
|
+
|
|
|
+ self?.effectFilterBeautyViewisHidden(isHidden: true)
|
|
|
+ }
|
|
|
+
|
|
|
+ if self?.musicView.alpha == 1 {
|
|
|
+
|
|
|
+ self?.musicViewisHidden(isHidden: true)
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
|
lazy var recorder: AliyunIRecorder? = {
|
|
|
-
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
let recorder = AliyunIRecorder.init(delegate: self, videoSize: CGSize(width: 720, height: 1280))
|
|
|
+
|
|
|
|
|
|
recorder?.preview = recorderPreview
|
|
|
+
|
|
|
+ let taskPathUrl =
|
|
|
+ PathURLManager.projectDateFormatPath(dateFormat: "yyyyMM", parentURL:
|
|
|
+ PathURLManager.projectVideosPath(parentURL:
|
|
|
+ PathURLManager.projectResourcesPath(parentURL:
|
|
|
+ PathURLManager.projectRecordssPath(parentURL:
|
|
|
+ PathURLManager.projectDocumentPath()))))!
|
|
|
|
|
|
- PathManager.clearRecrodPath()
|
|
|
+ PathURLManager.clearPath(pathURL: taskPathUrl)
|
|
|
+
|
|
|
|
|
|
- recorder?.taskPath = PathManager.aliyunVodCreateRecrodPath() ?? ""
|
|
|
+ recorder?.taskPath = taskPathUrl.path
|
|
|
+
|
|
|
+
|
|
|
+ let outputPathUrl =
|
|
|
+ PathURLManager.projectPathExtensionMp4(parentURL:
|
|
|
+ PathURLManager.projectFilePath(fileName:
|
|
|
+ PathURLManager.randomString(), parentURL:
|
|
|
+ PathURLManager.projectDateFormatPath(dateFormat: "yyyyMM", parentURL:
|
|
|
+ PathURLManager.projectVideosPath(parentURL:
|
|
|
+ PathURLManager.projectResourcesPath(parentURL:
|
|
|
+ PathURLManager.projectRecordssPath(parentURL:
|
|
|
+ PathURLManager.projectDocumentPath()))))))!
|
|
|
|
|
|
- recorder?.outputPath = PathManager.aliyunVodCreateRecrodOutputPath() ?? ""
|
|
|
+ recorder?.outputPath = outputPathUrl.path
|
|
|
+
|
|
|
+ recorder?.switchTorch(with: AliyunIRecorderTorchMode.off)
|
|
|
|
|
|
recorder?.beautifyStatus = true;
|
|
|
|
|
@@ -158,7 +254,6 @@ class PublishNewVideoPhotoView: BaseView {
|
|
|
return recorder!
|
|
|
}()
|
|
|
|
|
|
-
|
|
|
|
|
|
lazy var recorderPreview : PublishNewRecorderPreview = {
|
|
|
let recorderPreview = PublishNewRecorderPreview(frame: bounds)
|
|
@@ -169,12 +264,19 @@ class PublishNewVideoPhotoView: BaseView {
|
|
|
let publishNewVideoPhotoSetView = PublishNewVideoPhotoSetView()
|
|
|
return publishNewVideoPhotoSetView
|
|
|
}()
|
|
|
+
|
|
|
|
|
|
lazy var effectFilterBeautyView: PublishNewEffectFilterBeautyView = {
|
|
|
let effectFilterBeautyView = PublishNewEffectFilterBeautyView(frame: CGRect(x: 0, y: kScreenHeight, width: kScreenWidth, height: 48 + 125 + kSafeTabBarHeight))
|
|
|
return effectFilterBeautyView
|
|
|
}()
|
|
|
|
|
|
+
|
|
|
+ lazy var musicView : PublishNewMusicView = {
|
|
|
+ let musicView = PublishNewMusicView(frame: CGRect(x: 0, y: kScreenHeight, width: kScreenWidth, height: kScreenHeight - kSafeStatusBarHeight))
|
|
|
+ return musicView
|
|
|
+ }()
|
|
|
+
|
|
|
}
|
|
|
|
|
|
|
|
@@ -183,6 +285,7 @@ extension PublishNewVideoPhotoView {
|
|
|
|
|
|
|
|
|
func startTakeVideo() {
|
|
|
+
|
|
|
DispatchQueue.main.async {
|
|
|
[weak self] in
|
|
|
self?.recorder?.startRecording()
|
|
@@ -210,6 +313,7 @@ extension PublishNewVideoPhotoView {
|
|
|
publishNewVideoPhotoSetView.cameraFlipButton.isHidden = true
|
|
|
publishNewVideoPhotoSetView.filterButton.isHidden = true
|
|
|
publishNewVideoPhotoSetView.beautyButton.isHidden = true
|
|
|
+ publishNewVideoPhotoSetView.musicButton.isHidden = true
|
|
|
|
|
|
}
|
|
|
|
|
@@ -219,6 +323,7 @@ extension PublishNewVideoPhotoView {
|
|
|
publishNewVideoPhotoSetView.cameraFlipButton.isHidden = false
|
|
|
publishNewVideoPhotoSetView.filterButton.isHidden = false
|
|
|
publishNewVideoPhotoSetView.beautyButton.isHidden = false
|
|
|
+ publishNewVideoPhotoSetView.musicButton.isHidden = false
|
|
|
}
|
|
|
|
|
|
|
|
@@ -231,16 +336,14 @@ extension PublishNewVideoPhotoView {
|
|
|
|
|
|
|
|
|
func takePhoto() {
|
|
|
- DispatchQueue.main.async {
|
|
|
- [weak self] in
|
|
|
- self?.recorder?.takePhoto({ (image, rawImage) in
|
|
|
+ recorder?.takePhoto({(image, rawImage) in
|
|
|
+ DispatchQueue.main.async {
|
|
|
|
|
|
- let vc = UIViewController.topMost
|
|
|
let publishConfirmPhotoNewVC = PublishConfirmPhotoNewViewController()
|
|
|
publishConfirmPhotoNewVC.photoImg = image
|
|
|
- vc?.navigationController?.pushViewController(publishConfirmPhotoNewVC, animated: true)
|
|
|
- })
|
|
|
- }
|
|
|
+ UIViewController.topMost?.navigationController?.pushViewController(publishConfirmPhotoNewVC, animated: true)
|
|
|
+ }
|
|
|
+ })
|
|
|
}
|
|
|
|
|
|
func deleteVideo() {
|
|
@@ -338,18 +441,26 @@ extension PublishNewVideoPhotoView {
|
|
|
[weak self] in
|
|
|
self?.publishNewVideoPhotoSetView.progressView.alpha = alpha
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
closeMakeConstraints(duration: duration)
|
|
|
}
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
func closeMakeConstraints(duration:TimeInterval) {
|
|
|
if PublishNewViewModel.shared.publishNewRecorderType == .video {
|
|
|
publishNewVideoPhotoSetView.closeVideoUpMakeConstraints(duration: duration)
|
|
|
+
|
|
|
+ recorder?.switchTorch(with: AliyunIRecorderTorchMode.off)
|
|
|
+ publishNewVideoPhotoSetView.flashButton.setImage(kImage(name: "video_ico_flashlight_close"), for: UIControl.State.normal)
|
|
|
+
|
|
|
}else if PublishNewViewModel.shared.publishNewRecorderType == .photo {
|
|
|
publishNewVideoPhotoSetView.closePhotoUpMakeConstraints(duration: duration)
|
|
|
+
|
|
|
+ recorder?.switchTorch(with: AliyunIRecorderTorchMode.auto)
|
|
|
+ publishNewVideoPhotoSetView.flashButton.setImage(kImage(name: "video_ico_flashlight_auto"), for: UIControl.State.normal)
|
|
|
+
|
|
|
}
|
|
|
}
|
|
|
|
|
@@ -378,14 +489,18 @@ extension PublishNewVideoPhotoView {
|
|
|
}
|
|
|
|
|
|
|
|
|
-
|
|
|
+
|
|
|
|
|
|
|
|
|
func effectFilterBeautyViewisHidden(isHidden:Bool) {
|
|
|
var offsetY : CGFloat = kScreenHeight
|
|
|
if isHidden {
|
|
|
offsetY = kScreenHeight
|
|
|
- segmentedViewAlpha(alpha:1)
|
|
|
+ if recorderDuration == 0 {
|
|
|
+ segmentedViewAlpha(alpha:1)
|
|
|
+ }else {
|
|
|
+ segmentedViewAlpha(alpha:0)
|
|
|
+ }
|
|
|
|
|
|
recorderPreview.removetap()
|
|
|
}else {
|
|
@@ -407,6 +522,87 @@ extension PublishNewVideoPhotoView {
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+
|
|
|
+ func filterLess() {
|
|
|
+ if selectedIndex > 0 {
|
|
|
+ selectedIndex = selectedIndex - 1
|
|
|
+ }else {
|
|
|
+ selectedIndex = (aliyunFiltersModel?.filters?.count ?? 1) - 1
|
|
|
+ }
|
|
|
+
|
|
|
+ didSelectFilter()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ func filterPlus() {
|
|
|
+ if selectedIndex < ((aliyunFiltersModel?.filters?.count ?? 0) - 1) {
|
|
|
+ selectedIndex = selectedIndex + 1
|
|
|
+ }else {
|
|
|
+ selectedIndex = 0
|
|
|
+ }
|
|
|
+
|
|
|
+ didSelectFilter()
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ func didSelectFilter() {
|
|
|
+ let indexPath = IndexPath(row: self.selectedIndex , section: 0)
|
|
|
+ effectFilterBeautyView.effectFilterView.collectionView(effectFilterBeautyView.effectFilterView.collectionView, didSelectItemAt: indexPath)
|
|
|
+ effectFilterBeautyView.effectFilterView.collectionView.selectItem(at: indexPath, animated: true, scrollPosition: UICollectionView.ScrollPosition.centeredHorizontally)
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ func showFilterNameLabel(aliyunEffectFilter:AliyunEffectFilter) {
|
|
|
+
|
|
|
+ recorderPreview.filterNameLabel.alpha = 1
|
|
|
+ recorderPreview.filterNameLabel.text = aliyunEffectFilter.name
|
|
|
+ UIView.animate(withDuration: 2, animations: {
|
|
|
+ [weak self] in
|
|
|
+ self?.recorderPreview.filterNameLabel.alpha = 1
|
|
|
+ }, completion: {
|
|
|
+ [weak self] (finished) in
|
|
|
+ UIView.animate(withDuration: 2, animations: {
|
|
|
+ [weak self] in
|
|
|
+ self?.recorderPreview.filterNameLabel.alpha = 0
|
|
|
+ })
|
|
|
+ })
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ func musicViewisHidden(isHidden:Bool) {
|
|
|
+ var offsetY : CGFloat = kScreenHeight
|
|
|
+ if isHidden {
|
|
|
+ offsetY = kScreenHeight
|
|
|
+ if recorderDuration == 0 {
|
|
|
+ segmentedViewAlpha(alpha:1)
|
|
|
+ }else {
|
|
|
+ segmentedViewAlpha(alpha:0)
|
|
|
+ }
|
|
|
+
|
|
|
+ recorderPreview.removetap()
|
|
|
+ }else {
|
|
|
+ offsetY = kSafeStatusBarHeight
|
|
|
+ segmentedViewAlpha(alpha:0)
|
|
|
+
|
|
|
+ recorderPreview.addTap()
|
|
|
+ }
|
|
|
+ UIView.animate(withDuration: 0.5) {
|
|
|
+ [weak self] in
|
|
|
+ self?.musicView.frame = CGRect(x: 0, y: offsetY, width: kScreenWidth, height: kScreenHeight -
|
|
|
+ kSafeStatusBarHeight)
|
|
|
+ if isHidden {
|
|
|
+ self?.musicView.alpha = 0
|
|
|
+ self?.publishNewVideoPhotoSetView.alpha = 1
|
|
|
+ }else {
|
|
|
+ self?.musicView.alpha = 1
|
|
|
+ self?.publishNewVideoPhotoSetView.alpha = 0
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
|
|
@@ -555,6 +751,7 @@ extension PublishNewVideoPhotoView : AliyunIRecorderDelegate {
|
|
|
@param error 异常
|
|
|
*/
|
|
|
func recoderError(_ error: Error!) {
|
|
|
-
|
|
|
+ NXLLog(error)
|
|
|
+ SwiftProgressHUD.shared().showText("录制异常")
|
|
|
}
|
|
|
}
|