Pārlūkot izejas kodu

录制页 - Logic Fixed && 补充选中音乐效果逻辑

Chris 5 gadi atpakaļ
vecāks
revīzija
b48b58a95e

+ 1 - 1
RainbowPlanet/RainbowPlanet.xcodeproj/project.pbxproj

@@ -5161,8 +5161,8 @@
 		BD5CA89022DD719000364A67 /* PublishMusicAbout */ = {
 			isa = PBXGroup;
 			children = (
-				BDBC0AF122DDD7E800CA788E /* PublishMusicChooseView.swift */,
 				BD50F46F22E157F50077D4BF /* PublishRecordMusicView.swift */,
+				BDBC0AF122DDD7E800CA788E /* PublishMusicChooseView.swift */,
 				BDD9377622DF3B47002D11B3 /* PublishMusicListController.swift */,
 				BDD9377422DEF371002D11B3 /* PublishMusicListCell.swift */,
 				BD5CA89122DD73A500364A67 /* PublishMusicVolumnView.swift */,

+ 0 - 2
RainbowPlanet/RainbowPlanet/Manager/MusicPlayManager/MusicPlayManager.swift

@@ -20,8 +20,6 @@ class MusicPlayManager: NSObject {
     
     // 记录当前正在播放的音乐Id
     var curPlayingId: Int = -1
-    // 记录当前正在应用的音乐Id
-    var curChoosingId: Int = -1
     
     //播放器相关
     var playerItem: AVPlayerItem!

+ 1 - 2
RainbowPlanet/RainbowPlanet/Model/CommunityModel/CommunityRecommendMusicListModel.swift

@@ -44,14 +44,13 @@ class CommunityMusicItemModel : NSObject, Mappable{
     
     // 本地添加,用于控制状态
     var isPlaying : Bool? = false
-    var isChoosing : Bool? = false
     
     
     class func newInstance(map: Map) -> Mappable?{
         return CommunityMusicItemModel()
     }
     required init?(map: Map){}
-    private override init(){}
+    public override init(){}
     
     func mapping(map: Map)
     {

+ 5 - 0
RainbowPlanet/RainbowPlanet/Modules/PublishModule/AliyunVideo/AlivcShortVideo/ShortVideoFile/VideoEdit/Controller/AliyunEditViewController.m

@@ -604,6 +604,7 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resourceDeleteNoti:) name:AliyunEffectResourceDeleteNotification object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadMusicAndCombineNoti:) name:@"DownloadMusicAndCombineNoti" object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(changeAudioVolumn:) name:@"ChangeAudioVolumnNoti" object:nil];
+    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(musicViewDidClose) name:@"EditCloseMusicChooseViewNoti" object:nil];
 }
 
 - (void)removeNotifications {
@@ -626,6 +627,10 @@ AliyunIExporterCallback, AliyunIPlayerCallback, AliyunMusicPickViewControllerDel
     [self.editor setAudioMixWeight:_backAudioVolumn];
 }
 
+- (void)musicViewDidClose {
+    [self resume];
+}
+
 
 //资源删除通知
 - (void)resourceDeleteNoti:(NSNotification *)noti {

+ 37 - 52
RainbowPlanet/RainbowPlanet/Modules/PublishModule/AliyunVideo/AlivcShortVideo/ShortVideoFile/VideoRecord/Controller/AliyunMagicCameraViewController.m

@@ -17,7 +17,6 @@
 #import <AliyunVideoSDKPro/AliyunClipManager.h>
 #import <AliyunVideoSDKPro/AliyunHttpClient.h>
 #import <CoreMotion/CoreMotion.h>
-#import "AliyunMusicPickViewController.h"
 #import "AliyunPathManager.h"
 #import "MBProgressHUD.h"
 #import "AliyunEffectResourceModel.h"
@@ -42,7 +41,7 @@
 #import "RainbowPlanet-Swift.h"
 
 
-@interface AliyunMagicCameraViewController () <AliyunMusicPickViewControllerDelegate, UIGestureRecognizerDelegate, UIAlertViewDelegate, AliyunIRecorderDelegate, AliyunEffectFilter2ViewDelegate>
+@interface AliyunMagicCameraViewController () <UIGestureRecognizerDelegate, UIAlertViewDelegate, AliyunIRecorderDelegate, AliyunEffectFilter2ViewDelegate>
 {
     NSURLSessionDownloadTask *_downloadTask;
 }
@@ -97,8 +96,7 @@
 @property (nonatomic, strong) AlivcPushBeautyDataManager *beautyFaceDataManager_normal;     //普通美颜的数据管理器
 @property (nonatomic, strong) AlivcPushBeautyDataManager *beautyFaceDataManager_advanced;   //高级美颜的数据管理器
 @property (nonatomic, strong) AlivcPushBeautyDataManager *beautySkinDataManager;            //美肌的数据管理器
-@property (nonatomic, strong) AliyunMusicPickModel *music;  //之前应用的音乐
-@property (nonatomic, assign) NSInteger tab;  //之前应用的音乐的所属0远程 1本地
+@property (nonatomic, strong) NSString *curMusicUrl; //之前应用的音乐のUrl
 @property (nonatomic, strong) AliyunReachability *reachability;       //网络监听
 @property (nonatomic, strong) AliyunDBHelper *dbHelper; //数据库
 
@@ -217,8 +215,9 @@
 
 - (void)viewDidLoad {
     [super viewDidLoad];
-    _cameraRotate =90;
-    _needStopPreview =YES;
+    _cameraRotate = 90;
+    _needStopPreview = YES;
+    _curMusicUrl = @"";
     
     Class c = NSClassFromString(@"AliyunEffectPrestoreManager");
     NSObject *prestore = (NSObject *)[[c alloc] init];
@@ -447,15 +446,23 @@
 {
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appWillResignActive:) name:UIApplicationWillResignActiveNotification object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(appDidBecomeActive:) name:UIApplicationDidBecomeActiveNotification object:nil];
-    [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(resourceDelete:) name:AliyunEffectResourceDeleteNotification object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(musicViewDidClose) name:@"RecordCloseMusicChooseViewNoti" object:nil];
     [[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(downloadMusicAndCombineNoti:) name:@"RecordDownloadMusicAndCombineNoti" object:nil];
 }
 
 - (void)downloadMusicAndCombineNoti:(NSNotification *)noti {
     NSString *urlStr = noti.object;
-    NSLog(@"\n------receiveNoti.urlStr == %@", urlStr);
-    [self downloadFileFromServerWithUrlStr:urlStr];
+    self.curMusicUrl = urlStr;
+    
+    if ([urlStr isEqualToString:@""]) {
+        // 不选择音乐(清除音乐效果)
+        [_recorder applyMusic:nil];
+    } else {
+        [self downloadFileFromServerWithUrlStr:urlStr];
+    }
+    
+    // 音乐按钮动效设置
+    [self changeMusicButtonStatus];
 }
 
 - (void)musicViewDidClose {
@@ -469,16 +476,6 @@
     
 }
 
-/**
- 资源被删除的通知
-
- @param noti 通知对象
- */
-- (void)resourceDelete:(NSNotification *)noti{
-    
-}
-
-
 - (void)appWillResignActive:(id)sender
 {
     if ([self.navigationController.childViewControllers lastObject] != self) {
@@ -605,12 +602,10 @@
         NSString *musicFilePath = [filePath path];// 将NSURL转成NSString
         NSLog(@"\n------下载音乐成功!path == %@", musicFilePath);
         
-        
-        // FIXME: to be fixed
+        // 应用音乐效果
         AVURLAsset *asset = [AVURLAsset assetWithURL:[NSURL fileURLWithPath:musicFilePath]];
         CGFloat musicDuration = [asset avAssetVideoTrackDuration];
         
-        
         AliyunEffectMusic *effectMusic = [[AliyunEffectMusic alloc] initWithFile:musicFilePath];
         effectMusic.startTime = 0;
         effectMusic.duration = musicDuration;
@@ -656,6 +651,9 @@
     [super viewWillAppear:animated];
     
     _magicCameraView.musicButton.enabled = ![_clipManager partCount];
+    // 音乐按钮动效设置
+    [self changeMusicButtonStatus];
+    
     NSLog(@"%zd",[_clipManager partCount]);
     [[UIApplication sharedApplication] setIdleTimerDisabled:YES];//录制模块禁止自动熄屏
     [self startRetainCameraRotate];
@@ -837,15 +835,7 @@
 
 - (void)musicButtonClicked
 {
-//    AliyunMusicPickViewController *vc =[[AliyunMusicPickViewController alloc] init];
-//    vc.delegate = self;
-//    vc.duration = _clipManager.maxDuration;
-//    vc.selectedMusic = self.music;
-//    vc.selectedTab = self.tab;
-//    self.needStopPreview =NO;
-//    [self.navigationController pushViewController:vc animated:YES];
-    
-    self.musicView = [PublishRecordMusicView publishRecordMusicViewWithAttachedView:self.view];
+    self.musicView = [PublishRecordMusicView publishRecordMusicViewWithAttachedView:self.view curMusicUrl:self.curMusicUrl];
     if (self.hideSegmentBlock) {
         self.hideSegmentBlock(true);
         self.magicCameraView.rateView.hidden = true;
@@ -957,28 +947,23 @@
     [self.recorder setRate:rate];
 }
 
-#pragma mark - AliyunMusicPickViewControllerDelegate
-
--(void)didSelectMusic:(AliyunMusicPickModel *)music tab:(NSInteger)tab{
-    self.music = music;
-    self.tab = tab;
-    
-    if ([music.name isEqualToString:@"无音乐"] || !music.path || ![[NSFileManager defaultManager] fileExistsAtPath:music.path]) {
-        //清除音乐效果
-        [_recorder applyMusic:nil];
-        self.tab =0;
+// 改变音乐Btn的图片状态及动画效果
+- (void)changeMusicButtonStatus {
+    if(self.curMusicUrl && ![self.curMusicUrl isEqualToString:@""]){
+        // 添加动效
+        [_magicCameraView.musicButton setImage:[UIImage imageNamed:@"video_ico_music_pre"] forState:UIControlStateNormal];
+        
+        CABasicAnimation *rotateAnimate = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
+        rotateAnimate.fromValue = @(0);
+        rotateAnimate.toValue = @(M_PI * 2);
+        rotateAnimate.repeatCount = NSIntegerMax;
+        rotateAnimate.duration = 35;
+        [_magicCameraView.musicButton.imageView.layer addAnimation:rotateAnimate forKey:nil];
+        
     }else{
-        AliyunEffectMusic *effectMusic = [[AliyunEffectMusic alloc] initWithFile:music.path];
-        effectMusic.startTime = music.startTime;
-        effectMusic.duration = music.duration;
-        [_recorder applyMusic:effectMusic];
-        NSLog(@"%@",effectMusic.path);
-        NSLog(@"----------->:有path,有文件");
+        [_magicCameraView.musicButton setImage:_uiConfig.musicImage forState:UIControlStateNormal];
+        [_magicCameraView.musicButton.imageView.layer removeAllAnimations];
     }
-    
-}
-
--(void)didCancelPick {
 }
 
 #pragma mark - AliyunIRecorderDelegate -
@@ -1082,7 +1067,7 @@
         }else{
             [[AlivcShortVideoRoute shared]registerEditVideoPath:outputPath];
             [[AlivcShortVideoRoute shared]registerEditMediasPath:nil];
-            if(self.music && ![self.music.name isEqualToString:@"无音乐"]){
+            if(self.curMusicUrl && ![self.curMusicUrl isEqualToString:@""]){
                 [[AlivcShortVideoRoute shared] registerHasRecordMusic:YES];
             }else{
                  [[AlivcShortVideoRoute shared] registerHasRecordMusic:NO];

+ 3 - 2
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishMusicAbout/PublishMusicChooseView.swift

@@ -250,7 +250,7 @@ class PublishMusicChooseView: FWPopupView {
         
         view.cancelButton.rx.tap.subscribe(onNext: { (data) in            
             view.hide()
-            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "CloseMusicChooseViewNoti"), object: nil)
+            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "EditCloseMusicChooseViewNoti"), object: nil)
             
             MusicPlayManager.shared().destroyPlayer()
             MusicPlayManager.shared().curPlayingId = -1
@@ -270,6 +270,7 @@ class PublishMusicChooseView: FWPopupView {
         view.volumnButton.rx.tap.subscribe(onNext: { (data) in
             view.hide(popupDidDisappearBlock: { (view1) in
                 _ = PublishMusicVolumnView.publishMusicVolumnView(attachedView: attachedView)
+                NotificationCenter.default.post(name: NSNotification.Name(rawValue: "EditCloseMusicChooseViewNoti"), object: nil)
             })
             
         }).disposed(by: view.disposeBag)
@@ -333,7 +334,7 @@ extension PublishMusicChooseView :JXSegmentedListContainerViewDataSource {
         listVc.chooseMusicClosure = {
             [weak self] (musicUrl) in
             NotificationCenter.default.post(name: NSNotification.Name(rawValue: "DownloadMusicAndCombineNoti"), object: musicUrl)
-            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "CloseMusicChooseViewNoti"), object: nil)
+            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "EditCloseMusicChooseViewNoti"), object: nil)
             
             MusicPlayManager.shared().destroyPlayer()
             MusicPlayManager.shared().curPlayingId = -1

+ 13 - 1
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishMusicAbout/PublishMusicListCell.swift

@@ -24,7 +24,19 @@ class PublishMusicListCell: UITableViewCell {
                 useButton.isHidden = true
             }
             
-            if self.musicItemMdl?.isChoosing == true {
+            // 不选择音乐
+            if self.musicItemMdl?.id == -1 {
+                iconImageView.isHidden = true
+                curPlayImageView.isHidden = true
+                useButton.isHidden = true
+            }
+        }
+    }
+    
+    var curMusicUrl: String? {
+        didSet {
+            // 是否为当前选中的音乐
+            if self.curMusicUrl == self.musicItemMdl?.url && self.musicItemMdl?.id != -1 {
                 curPlayImageView.isHidden = false
             } else {
                 curPlayImageView.isHidden = true

+ 18 - 17
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishMusicAbout/PublishMusicListController.swift

@@ -23,6 +23,8 @@ class PublishMusicListController: BaseViewController {
     typealias ChooseMusicClosure = (_ musicUrl: String) -> Void
     var chooseMusicClosure : ChooseMusicClosure?
     
+    var curMusicUrl: String?
+    
     // 推荐下の音乐
     var isReccomendList: Bool? {
         didSet {
@@ -49,11 +51,7 @@ class PublishMusicListController: BaseViewController {
         navigationBar.isHidden = true
         view.backgroundColor = UIColor.clear
         
-        view.addSubview(tableView)
-        let emptyView = DIYEmptyView.empty(with: kImage(name: "default_page_data"), titleStr: nil, detailStr: "当前暂无数据")
-        emptyView!.contentViewY = kScaleValue(value: 182)
-        tableView.ly_emptyView = emptyView
-        tableView.ly_startLoading()
+        view.addSubview(tableView)        
     }
     
     override func setupLayouts() {
@@ -89,6 +87,7 @@ extension PublishMusicListController : UITableViewDelegate, UITableViewDataSourc
     func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
         let cell = PublishMusicListCell.cellWith(tableView: tableView, indexPath: indexPath)
         cell.musicItemMdl = musicItemMdlArr[indexPath.row]
+        cell.curMusicUrl  = curMusicUrl
         cell.useClickClosure = {
             [weak self] in
             let curChoosingId = self?.musicItemMdlArr[indexPath.row].id!
@@ -110,8 +109,7 @@ extension PublishMusicListController : UITableViewDelegate, UITableViewDataSourc
         
         let musicId = musicItemMdlArr[indexPath.row].id!
         MusicPlayManager.shared().curPlayingId = musicId
-        let curChoosingId = MusicPlayManager.shared().curPlayingId
-        self.resetCellStatusWith(musicId, curChoosingId)
+        self.resetCellStatusWith(musicId)
     }
     
     func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
@@ -146,8 +144,7 @@ extension PublishMusicListController : JXSegmentedListContainerViewListDelegate
     }
     func listDidAppear() {
         let curPlayingId = MusicPlayManager.shared().curPlayingId
-        let curChoosingId = MusicPlayManager.shared().curChoosingId
-        self.resetCellStatusWith(curPlayingId, curChoosingId)
+        self.resetCellStatusWith(curPlayingId)
     }
     func listDidDisappear() {
         
@@ -164,6 +161,7 @@ extension PublishMusicListController {
                 if recommendMusicListModel?.pagination?.currentPage == 1 {
                     self?.musicItemMdlArr.removeAll()
                 }
+                self?.createDisableMusicItem()
                 self?.musicItemMdlArr = (self?.musicItemMdlArr)! + (recommendMusicListModel?.data!)!
                 
                 self?.tableView.reloadData()
@@ -185,6 +183,7 @@ extension PublishMusicListController {
                 if categoryMusicListModel?.pagination?.currentPage == 1 {
                     self?.musicItemMdlArr.removeAll()
                 }
+                self?.createDisableMusicItem()
                 self?.musicItemMdlArr = (self?.musicItemMdlArr)! + (categoryMusicListModel?.data!)!
                 
                 self?.tableView.reloadData()
@@ -199,7 +198,7 @@ extension PublishMusicListController {
     }
     
     // 重置播放状态
-    func resetCellStatusWith(_ playingId: Int, _ choosingId: Int) -> Void {
+    func resetCellStatusWith(_ playingId: Int) -> Void {
         for musicMdl in musicItemMdlArr {
             // 播放状态判断
             if playingId == musicMdl.id {
@@ -207,15 +206,17 @@ extension PublishMusicListController {
             } else {
                 musicMdl.isPlaying = false
             }
-            
-            // 应用状态判断
-            if choosingId == musicMdl.id {
-                musicMdl.isChoosing = true
-            } else {
-                musicMdl.isChoosing = false
-            }
         }
         tableView.reloadData()
     }
     
+    // 创建"不选择音乐"Item
+    func createDisableMusicItem() {
+        let disMusicItem = CommunityMusicItemModel()
+        disMusicItem.id = -1
+        disMusicItem.name = "不选择音乐"
+        disMusicItem.url = ""
+        self.musicItemMdlArr.append(disMusicItem)
+    }
+    
 }

+ 25 - 11
RainbowPlanet/RainbowPlanet/Modules/PublishModule/PublishMusicAbout/PublishRecordMusicView.swift

@@ -19,6 +19,8 @@ class PublishRecordMusicView: FWPopupView {
     typealias RecommendClosure = () -> Void
     var recommendClosure : RecommendClosure?
     
+    var curMusicUrl: String?
+    
     override init(frame: CGRect) {
         super.init(frame: frame)
         setupViews()
@@ -175,9 +177,10 @@ class PublishRecordMusicView: FWPopupView {
     }()
     
     /// 初始化View    
-    @objc class func publishRecordMusicView(attachedView:UIView) -> PublishRecordMusicView {
+    @objc class func publishRecordMusicView(attachedView:UIView, curMusicUrl:String) -> PublishRecordMusicView {
         let view = PublishRecordMusicView()
         view.attachedView = attachedView
+        view.curMusicUrl = curMusicUrl
         let vProperty = FWPopupViewProperty()
         vProperty.popupCustomAlignment = .bottomCenter
         vProperty.popupViewEdgeInsets = UIEdgeInsets(top: 0, left: 0, bottom: 0, right: 0)
@@ -247,28 +250,39 @@ extension PublishRecordMusicView :JXSegmentedListContainerViewDataSource {
     }
     func listContainerView(_ listContainerView: JXSegmentedListContainerView, initListAt index: Int) -> JXSegmentedListContainerViewListDelegate {
         let listVc = PublishMusicListController()
+        listVc.curMusicUrl = self.curMusicUrl
         if index == 0 {
             listVc.isReccomendList = true
         } else {
             listVc.categoryItemMdl = categoryListMdlArr![index-1]
         }
         listVc.playMusicClosure = {
-            (musicUrl) in
-            MusicPlayManager.shared().initPlay()
-            MusicPlayManager.shared().audioUrl = musicUrl
-            MusicPlayManager.shared().playAudio()
+            [weak self] (musicUrl) in
+            if musicUrl == "" {
+                // 点击了不选择音乐
+                self?.chooseMusicAction(musicUrl)
+            } else {
+                MusicPlayManager.shared().initPlay()
+                MusicPlayManager.shared().audioUrl = musicUrl
+                MusicPlayManager.shared().playAudio()
+            }
+            
         }
         listVc.chooseMusicClosure = {
             [weak self] (musicUrl) in
-            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "RecordDownloadMusicAndCombineNoti"), object: musicUrl)
-            NotificationCenter.default.post(name: NSNotification.Name(rawValue: "RecordCloseMusicChooseViewNoti"), object: nil)
-            
-            MusicPlayManager.shared().destroyPlayer()
-            MusicPlayManager.shared().curPlayingId = -1
-            self?.hide()
+            self?.chooseMusicAction(musicUrl)
         }
         return listVc
     }
+    
+    func chooseMusicAction(_ musicUrl: String) {
+        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "RecordDownloadMusicAndCombineNoti"), object: musicUrl)
+        NotificationCenter.default.post(name: NSNotification.Name(rawValue: "RecordCloseMusicChooseViewNoti"), object: nil)
+        
+        MusicPlayManager.shared().destroyPlayer()
+        MusicPlayManager.shared().curPlayingId = -1
+        self.hide()
+    }
 }
 
 // MARK: - 网络请求