| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494 |
- //
- // YunMusicPlayVC.m
- // BuguLive
- //
- // Created by 岳克奎 on 16/11/14.
- // Copyright © 2016年 xfg. All rights reserved.
- //
- #import "YunMusicPlayVC.h"
- @interface YunMusicPlayVC ()<YunMusicSoundEffectVCDelegate>
- @property(nonatomic, assign) NSInteger sdktype;
- @end
- @implementation YunMusicPlayVC
- - (void)viewDidLoad
- {
- [super viewDidLoad];
-
- _musicPlayVC_Pan_Ges = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panGesClick:)];
- [self.view addGestureRecognizer:_musicPlayVC_Pan_Ges];
- }
- - (void)panGesClick:(UIPanGestureRecognizer *)pan
- {
- if (_yunMusicPlayVCPanGesBlock)
- {
- _yunMusicPlayVCPanGesBlock(self,_musicPlayVC_Pan_Ges);
- }
- }
- #pragma mark 音效页面
- - (IBAction)soundefectSet:(UIButton *)sender
- {
- YunMusicSoundEffectVC *soundsEffect_VC = [YunMusicSoundEffectVC showYunMusicSoundEffectVCInVC:_fwTLiveController inView:_fwTLiveController.liveServiceController.liveUIViewController.liveView showFrame:CGRectMake(0,0,kScreenW, kScreenH) oldBGMValue:_recordBgmValue oldMicValue:_recordMicValue];
- soundsEffect_VC.delegate = self;
- }
- #pragma mark- 关闭music
- - (IBAction)soundEndBtnClick:(UIButton *)sender
- {
- // 结束因为播放
-
- if(_sdktype == 0)
- {
- [self.fwTLiveController.publishController.txLivePublisher stopBGM];
- }
- else
- {
- [self.fwTKsyController.agoraLinkMicStreamerController.gPUStreamerKit.bgmPlayer stopPlayBgm];
- }
-
- // 移除用代理 因为音效VC如果存在也要退出
- // 移除本页面
- [self removeMusicPlayVC];
-
- self.musicPlaySuperVC = nil;
- }
- #pragma mark- 暂停和播放 切换
- /**
- 暂停和播放 切换
- @param sender fw_relive_start:未播放 fw_relive_suspend:正在播放
- */
- - (IBAction)pauseMusic:(UIButton *)sender
- {
- _yunMusicPlaying = !_yunMusicPlaying;
- if (_yunMusicPlaying)
- {
- if(_sdktype == 0)
- {
- [self.fwTLiveController.publishController.txLivePublisher pauseBGM];
- }
- else
- {
- [self.fwTKsyController.agoraLinkMicStreamerController.gPUStreamerKit.bgmPlayer pauseBgm];
- }
- // 暂停状态 转为播放
- [_pauseMusic_Btn setImage:[UIImage imageNamed:@"fw_relive_suspend"] forState:UIControlStateNormal];
- // [self.fwTLiveController.publishController.txLivePublisher resumeBGM];
-
- if(_sdktype == 0)
- {
- [self.fwTLiveController.publishController.txLivePublisher resumeBGM];
- }
- else
- {
- [self.fwTKsyController.agoraLinkMicStreamerController.gPUStreamerKit.bgmPlayer resumeBgm];
- }
-
- if (self.recordMusicCurrentTime+200>= self.recordMusicTotalTime && self.recordMusicModel &&_yunMusicPlaying&&self.recordMusicTotalTime/1000>10)
- {
- // 需要重新播放
- __weak YunMusicPlayVC *weak_Self= self;
- [[MusicCenterManager shareManager] showMusicLRCofLRCDataStr:weak_Self.recordMusicModel.title musicNameStr:weak_Self.recordMusicModel.title musicSingerStr:weak_Self.recordMusicModel.title complete:^(BOOL finished, NSMutableArray *lrcModelMArray, NSMutableArray *lrcPointTimeStrArray)
- {
- // 歌词处理完毕 得到数据 将处理好的数据 传给lrcView,等待歌词开启的时候使用
- weak_Self.lrcView.lrcUpLab.text = @" ";
- weak_Self.lrcView.lrcDowmLab.text = @" ";
- weak_Self.lrcView.lrcModelMArray = lrcModelMArray;
-
- weak_Self.lrcView.lrcTimePointMArray = lrcPointTimeStrArray;
-
- // 开始播放
- // weak_Self.yunMusicPlaying = [weak_Self.fwTLiveController.publishController.txLivePublisher playBGM:[weak_Self getFullFilePath:weak_Self.recordMusicModel.title] withBeginNotify:^(NSInteger errCode) {
- //
- // } withProgressNotify:^(NSInteger progressMS, NSInteger durationMS) {
- //
- // // 再检修播放
- // weak_Self.recordMusicTotalTime = durationMS;
- // weak_Self.recordMusicCurrentTime = progressMS;
- // if (progressMS+200>=durationMS)
- // {
- // weak_Self.yunMusicPlaying = NO;
- // [weak_Self.pauseMusic_Btn setImage:[UIImage imageNamed:@"fw_relive_start"] forState:UIControlStateNormal];
- // }
- //
- // [ weak_Self.lrcView setCurrentTime:progressMS*0.001 musicTotalTime:durationMS*0.001 present:durationMS ==0 ?0:(CGFloat)progressMS/durationMS];
- //
- // }andCompleteNotify:^(NSInteger errCode) {
- //
- // }];
- }];
- }
- }
- else
- {
- if(_sdktype == 0)
- {
- [self.fwTLiveController.publishController.txLivePublisher pauseBGM];
- }
- else
- {
- [self.fwTKsyController.agoraLinkMicStreamerController.gPUStreamerKit.bgmPlayer pauseBgm];
- }
- [_pauseMusic_Btn setImage:[UIImage imageNamed:@"fw_relive_start"] forState:UIControlStateNormal];
- }
- }
- - (void)showYunMusicPlayInVC:(UIViewController*)vc inview:(UIView*)inview showframe:(CGRect)showframe myPlayType:(NSInteger)playType
- {
- // 1 选择music vc
- choseMuiscVC* chosevc = [[choseMuiscVC alloc]initWithNibName:@"choseMuiscVC" bundle:nil];
- // 2 nav
- UIViewController* nullvc = UIViewController.new;
- UINavigationController * nav = [[UINavigationController alloc]initWithRootViewController:chosevc];
- nav.navigationBarHidden = YES;
- nav.view.backgroundColor = [UIColor clearColor];
- nav.modalPresentationStyle = UIModalPresentationOverCurrentContext;
-
- self.musicPlaySuperVC = vc;
- // 3
- __block UIViewController *tmpVC = self.musicPlaySuperVC;
- chosevc.mitblock = ^(musiceModel* chosemusic)
- {
- [nav dismissViewControllerAnimated:YES completion:^{
-
- if(chosemusic)
- {
- // 选择了就开始放歌了
- [YunMusicPlayVC showYunMusicPlayInVC:tmpVC inview:inview musicFrame:showframe musicmodel:chosemusic PlayType:playType];
- tmpVC = nil;
- }
- }];
- };
- // 跳转到choseMusicVC
- [vc presentViewController:nav animated:NO completion:^{
-
- }];
- }
- #pragma mark -public methods ------------------------------------------ 公有方法区域 -----------------------------------------
- - (NSInteger)fileSizeAtPath:(NSString*) filePath
- {
- NSFileManager* manager = [NSFileManager defaultManager];
-
- if ([manager fileExistsAtPath:filePath])
- {
- return (NSInteger)[[manager attributesOfItemAtPath:filePath error:nil] fileSize];
- }
- return 0;
- }
- #pragma mark 加载到 直播VC上
- + (YunMusicPlayVC *)showYunMusicPlayInVC:(UIViewController*)vc inview:(UIView*)inview musicFrame:(CGRect)musicFrame musicmodel:(musiceModel*)musicmodel PlayType:(NSInteger)playType
- {
- if(playType == 0)
- {
- BGTLiveController *live_VC = (BGTLiveController *)vc;
- for (UIView *one_View in live_VC.liveServiceController.liveUIViewController.liveView.subviews)
- {
- if ([one_View.nextResponder isKindOfClass:[YunMusicPlayVC class]])
- {
- [live_VC removeChild:(YunMusicPlayVC *)one_View.nextResponder];
- [one_View removeFromSuperview];
- }
- }
-
- YunMusicPlayVC *music_VC = [[YunMusicPlayVC alloc]initWithNibName:@"YunMusicPlayVC" bundle:nil];
- music_VC.recordBgmValue = 1.0;
- music_VC.recordMicValue = 1.0;
- music_VC.sdktype = playType;
- MUSIC_CENTER_MANAGER.dataDelegate = music_VC;
- [vc addChild:music_VC];
- [inview addSubview:music_VC.view];
- music_VC.view.frame = musicFrame;
- music_VC.fwTLiveController =(BGTLiveController *)vc;
- if (music_VC.fwTLiveController.publishController.txLivePublisher)
- {
-
- }
- // 歌词处理
- __weak YunMusicPlayVC *weak_playVC = music_VC;
- music_VC.recordMusicModel = musicmodel;
- [[MusicCenterManager shareManager] showMusicLRCofLRCDataStr:musicmodel.title musicNameStr:musicmodel.title musicSingerStr:musicmodel.title complete:^(BOOL finished, NSMutableArray *lrcModelMArray, NSMutableArray *lrcPointTimeStrArray)
- {
- // 歌词处理完毕 得到数据 将处理好的数据 传给lrcView,等待歌词开启的时候使用
- weak_playVC.lrcView.lrcUpLab.text = @" ";
- weak_playVC.lrcView.lrcDowmLab.text = @" ";
- weak_playVC.lrcView.lrcModelMArray = lrcModelMArray;
-
- weak_playVC.lrcView.lrcTimePointMArray = lrcPointTimeStrArray;
-
- NSLog(@"==========filePath:%@",[music_VC getFullFilePath:musicmodel.title]);
- NSLog(@"eqqew ========== %ld",(long)[music_VC fileSizeAtPath:[music_VC getFullFilePath:musicmodel.title]]);
- // 开始播放,先结束之前播放的BGM
- [music_VC.fwTLiveController.publishController.txLivePublisher stopBGM];
-
- // weak_playVC.yunMusicPlaying = [music_VC.fwTLiveController.publishController.txLivePublisher playBGM:[music_VC getFullFilePath:musicmodel.title]];
- weak_playVC.yunMusicPlaying = [music_VC.fwTLiveController.publishController.txLivePublisher playBGM:[music_VC getFullFilePath:musicmodel.title] withBeginNotify:^(NSInteger errCode) {
- } withProgressNotify:^(NSInteger progressMS, NSInteger durationMS) {
- // 再检修播放
- weak_playVC.recordMusicTotalTime = durationMS;
- weak_playVC.recordMusicCurrentTime = progressMS;
- if (progressMS+200>=durationMS)
- {
- weak_playVC.yunMusicPlaying = NO;
- [weak_playVC.pauseMusic_Btn setImage:[UIImage imageNamed:@"fw_relive_start"] forState:UIControlStateNormal];
- }
- [weak_playVC.lrcView setCurrentTime:progressMS*0.001 musicTotalTime:durationMS*0.001 present:durationMS ==0 ?0:(CGFloat)progressMS/durationMS];
- }andCompleteNotify:^(NSInteger errCode) {
- }];
-
- NSLog(@"%d",weak_playVC.yunMusicPlaying);
- }];
-
- music_VC.musicName_Lab.text = [NSString stringWithFormat:@"%@(%@)",musicmodel.title,musicmodel.title];
- music_VC.yunMusicPlayVCPanGesBlock =^(YunMusicPlayVC* yunMusicPlayVC,UIPanGestureRecognizer *pan)
- {
- CGPoint panPoint = [pan locationInView:yunMusicPlayVC.fwTLiveController.liveServiceController.liveUIViewController.liveView];
- CGPoint panPoint_moveValue = [pan translationInView:yunMusicPlayVC.fwTLiveController.liveServiceController.liveUIViewController.liveView];
- [yunMusicPlayVC setPanGesForYunMusicVC:panPoint withModeValue:panPoint_moveValue showInVC:yunMusicPlayVC];
-
- };
-
- return music_VC;
- }
- //新加的金山音乐播放
- else
- {
- BGKSYLiveController *live_VC = (BGKSYLiveController *)vc;
- for (UIView *one_View in live_VC.liveServiceController.liveUIViewController.liveView.subviews)
- {
- if ([one_View.nextResponder isKindOfClass:[YunMusicPlayVC class]])
- {
- [live_VC removeChild:(YunMusicPlayVC *)one_View.nextResponder];
- [one_View removeFromSuperview];
- }
- }
-
- YunMusicPlayVC *music_VC = [[YunMusicPlayVC alloc]initWithNibName:@"YunMusicPlayVC" bundle:nil];
- music_VC.recordBgmValue = 1.0;
- music_VC.recordMicValue = 1.0;
- music_VC.sdktype = playType;
- MUSIC_CENTER_MANAGER.dataDelegate = music_VC;
- [vc addChild:music_VC];
- [inview addSubview:music_VC.view];
- music_VC.view.frame = musicFrame;
- music_VC.fwTKsyController =(BGKSYLiveController *)vc;
- // 歌词处理
- __weak YunMusicPlayVC *weak_playVC = music_VC;
- music_VC.recordMusicModel = musicmodel;
- [[MusicCenterManager shareManager] showMusicLRCofLRCDataStr:musicmodel.title musicNameStr:musicmodel.title musicSingerStr:musicmodel.title complete:^(BOOL finished, NSMutableArray *lrcModelMArray, NSMutableArray *lrcPointTimeStrArray)
- {
- // 歌词处理完毕 得到数据 将处理好的数据 传给lrcView,等待歌词开启的时候使用
- weak_playVC.lrcView.lrcUpLab.text = @" ";
- weak_playVC.lrcView.lrcDowmLab.text = @" ";
- weak_playVC.lrcView.lrcModelMArray = lrcModelMArray;
-
- weak_playVC.lrcView.lrcTimePointMArray = lrcPointTimeStrArray;
-
- NSLog(@"==========filePath:%@",[music_VC getFullFilePath:musicmodel.title]);
- NSLog(@"eqqew ========== %ld",(long)[music_VC fileSizeAtPath:[music_VC getFullFilePath:musicmodel.title]]);
- // 开始播放,先结束之前播放的BGM
- [music_VC.fwTKsyController.agoraLinkMicStreamerController.gPUStreamerKit.bgmPlayer stopPlayBgm];
- // [music_VC.fwTLiveController.publishController.txLivePublisher stopBGM];
-
-
- weak_playVC.yunMusicPlaying = [music_VC.fwTKsyController.agoraLinkMicStreamerController.gPUStreamerKit.bgmPlayer startPlayBgm:[music_VC getFullFilePath:musicmodel.title] isLoop:YES];
-
- // weak_playVC.yunMusicPlaying = [music_VC.fwTLiveController.publishController.txLivePublisher playBGM:[music_VC getFullFilePath:musicmodel.title] withBeginNotify:^(NSInteger errCode) {
- //
- // } withProgressNotify:^(NSInteger progressMS, NSInteger durationMS) {
- //
- // // 再检修播放
- // weak_playVC.recordMusicTotalTime = durationMS;
- // weak_playVC.recordMusicCurrentTime = progressMS;
- // if (progressMS+200>=durationMS)
- // {
- // weak_playVC.yunMusicPlaying = NO;
- // [weak_playVC.pauseMusic_Btn setImage:[UIImage imageNamed:@"fw_relive_start"] forState:UIControlStateNormal];
- // }
- // [weak_playVC.lrcView setCurrentTime:progressMS*0.001 musicTotalTime:durationMS*0.001 present:durationMS ==0 ?0:(CGFloat)progressMS/durationMS];
- //
- // }andCompleteNotify:^(NSInteger errCode) {
- //
- // }];
- }];
-
- music_VC.musicName_Lab.text = [NSString stringWithFormat:@"%@(%@)",musicmodel.title,musicmodel.title];
- music_VC.yunMusicPlayVCPanGesBlock =^(YunMusicPlayVC* yunMusicPlayVC,UIPanGestureRecognizer *pan)
- {
- CGPoint panPoint = [pan locationInView:yunMusicPlayVC.fwTLiveController.liveServiceController.liveUIViewController.liveView];
- CGPoint panPoint_moveValue = [pan translationInView:yunMusicPlayVC.fwTLiveController.liveServiceController.liveUIViewController.liveView];
- [yunMusicPlayVC setPanGesForYunMusicVC:panPoint withModeValue:panPoint_moveValue showInVC:yunMusicPlayVC];
-
- };
-
- return music_VC;
- }
-
-
- }
- #pragma mark 完整的音乐文件地址
- - (NSString*)getFullFilePath:(NSString *)filePathStr
- {
- NSString *str = [NSString stringWithFormat:@"/Documents/%@/%@",@"music",filePathStr];
- if (str && ![str isEqualToString:@""])
- {
- return [NSHomeDirectory() stringByAppendingString:str];
- }
- return NSHomeDirectory();
- }
- #pragma -custom delegate ---------------------------------------------------自定义代理
- - (void)changeMusicBtnOfPlayStatewWithMusicPlayState:(BOOL)musicPlaySate
- {
- _yunMusicPlaying = !musicPlaySate;
- [self pauseMusic:nil];
- }
- #pragma mark - 音频效果的代理/调节伴奏 bgm
- - (void)setBGMValue:(CGFloat )bgmValue
- {
- _recordBgmValue = bgmValue;
-
- if(_sdktype == 0)
- {
- [self.fwTLiveController.publishController.txLivePublisher setBGMVolume:bgmValue];
- }
- else
- {
- [self.fwTKsyController.agoraLinkMicStreamerController.gPUStreamerKit.bgmPlayer setBgmVolume:bgmValue];
- }
-
- NSLog(@" current bgmValue = %f",bgmValue);
- }
- #pragma mark -调节人声 mic
- - (void)setMicValue:(CGFloat )micValue
- {
- _recordMicValue = micValue;
- if(_sdktype == 0)
- {
- [self.fwTLiveController.publishController.txLivePublisher setMicVolume:micValue];
- }
- else
- {
- }
- NSLog(@" current micValue = %f",micValue);
- }
- #pragma mark - 移除 VC
- - (void)removeMusicPlayVC
- {
- if(_sdktype == 0)
- {
- for (UIViewController *vc in self.fwTLiveController.childViewControllers)
- {
- if ([vc isKindOfClass:[self class]])
- {
-
- [self.fwTLiveController removeChild:vc];
- [vc.view removeFromSuperview];
- }
- }
- }
- else
- {
- for (UIViewController *vc in self.fwTKsyController.childViewControllers)
- {
- if ([vc isKindOfClass:[self class]])
- {
-
- [self.fwTKsyController removeChild:vc];
- [vc.view removeFromSuperview];
- }
- }
- }
- }
- #pragma mark ------------处理pan移动问题
- /**
- 移动到边界处理,当移动屏幕超出 默认window(界面)时,结束手势状态下,动画设置回弹效果 确保在屏幕内部
- @param panPoint 点击的点
- @param moveVlue 实时移动的店
- @param yunMusicPlayVC YunMusicPlayVC
- */
- - (void)setPanGesForYunMusicVC:(CGPoint)panPoint withModeValue:(CGPoint)moveVlue showInVC:(YunMusicPlayVC *)yunMusicPlayVC
- {
- yunMusicPlayVC.view.transform = CGAffineTransformTranslate( yunMusicPlayVC.view.transform, moveVlue.x, moveVlue.y);
- [yunMusicPlayVC.musicPlayVC_Pan_Ges setTranslation:CGPointZero inView:yunMusicPlayVC.view];
-
- if (yunMusicPlayVC.musicPlayVC_Pan_Ges.state == UIGestureRecognizerStateBegan)
- {
- }
-
- if (yunMusicPlayVC.musicPlayVC_Pan_Ges.state == UIGestureRecognizerStateChanged)
- {
- }
-
- if (yunMusicPlayVC.musicPlayVC_Pan_Ges.state == UIGestureRecognizerStateEnded)
- {
- if(yunMusicPlayVC.view.x<0)
- {
- [UIView animateWithDuration:0.2 animations:^{
- yunMusicPlayVC.view.x = 0;
- }completion:^(BOOL finished) {
-
- }];
- }
-
- if (yunMusicPlayVC.view.frame.origin.y<50)
- {
- [UIView animateWithDuration:0.2 animations:^{
- yunMusicPlayVC.view.y = 50;
- }completion:^(BOOL finished) {
-
- }];
- }
-
- if (yunMusicPlayVC.view.frame.origin.y> kScreenH - 300)
- {
- [UIView animateWithDuration:0.2 animations:^{
- yunMusicPlayVC.view.y = kScreenH-300;
- } completion:^(BOOL finished) {
-
- }];
-
- }
-
- if (yunMusicPlayVC.view.x>kScreenW-0.4*kScreenW)
- {
- [UIView animateWithDuration:0.2 animations:^{
- yunMusicPlayVC.view.x = kScreenW-0.4*kScreenW;
- } completion:^(BOOL finished) {
-
- }];
- }
- }
- }
- - (void)setRecordMusicModel:(musiceModel *)recordMusicModel
- {
- _recordMusicModel = recordMusicModel;
- }
- - (void)didReceiveMemoryWarning
- {
- [super didReceiveMemoryWarning];
- }
- @end
|