| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265 |
- //
- // TCVideoEditViewController.m
- // TCLVBIMDemo
- //
- // Created by xiang zhang on 2017/4/10.
- // Copyright © 2017年 tencent. All rights reserved.
- //
- #import "TCVideoEditViewController.h"
- #import <TXLiteAVSDK_Professional/TXVideoEditer.h>
- //#import "TXVideoEditer.h"
- #import <MediaPlayer/MPMediaPickerController.h>
- #import <AVFoundation/AVFoundation.h>
- #import "TCVideoRangeSlider.h"
- #import "TCVideoRangeConst.h"
- #import "TCVideoPublishController.h"
- //#import "UIView+AdditionsX12.h"
- #import "UIColor+MLPFlatColors.h"
- #import "TCFilterSettingView.h"
- #import "TCVideoPreview.h"
- #import "TCBottomTabBar.h"
- #import "TCVideoCutView.h"
- #import "TCMusicMixView.h"
- #import "TCTextAddView.h"
- #import "YBVideoMusicView.h"
- #import "EffectSelectView.h"
- #import "TimeSelectView.h"
- #import <SDWebImage/SDWebImageDownloader.h>
- #import "YBProgressObj.h"
- #import "YBTakeSameVideoVC.h"
- #import <MediaPlayer/MediaPlayer.h>
- typedef NS_ENUM(NSInteger,ActionType) {
- ActionType_Save,
- ActionType_Publish,
- ActionType_Save_Publish,
- };
- typedef NS_ENUM(NSInteger,TimeType) {
- TimeType_Clear,
- TimeType_Back,
- TimeType_Repeat,
- TimeType_Speed,
- };
- @interface TCVideoEditViewController ()<TXVideoGenerateListener,TCVideoPreviewDelegate, TCVideoPreviewDelegate, TCFilterSettingViewDelegate, TCBottomTabBarDelegate, TCVideoCutViewDelegate, TCMusicMixViewDelegate, MPMediaPickerControllerDelegate, UIActionSheetDelegate,VideoEffectViewDelegate,TimeSelectViewDelegate>
- @property(nonatomic,strong)UIButton *backBtn;
- @property(nonatomic,strong)UIButton *selMusicBtn; //选择音乐
- @property(nonatomic,strong)UIButton *selVolumeBtn; //选择音量
- /** 底部按钮组合:特效、封面、滤镜、下一步 */
- @property(nonatomic,strong)UIView *botBtnMix;
- @property(nonatomic,strong)UIButton *effectBtn;
- @property(nonatomic,strong)UIButton *coverBtn;
- @property(nonatomic,strong)UIButton *filterfBtn;
- @property(nonatomic,strong)UIButton *nextBtn;
- /** 底部功能组合:botBar、videoRangeSlider、剪裁、时间特效、其他特效 */
- @property(nonatomic,strong)UIView *botFunctionMix;
- @property(nonatomic,strong)TCBottomTabBar *bottomBar;
- @property(nonatomic,strong) UILabel *cutTipsLabel;
- @property(nonatomic,strong)TCVideoCutView *videoCutView;
- @property(nonatomic,strong)TCFilterSettingView *filterView;
- @property(nonatomic,strong)TCMusicMixView *musixMixView;
- @property(nonatomic,strong)EffectSelectView *effectSelectView; //动效选择
- @property(nonatomic,strong)TimeSelectView *timeSelectView; //时间特效栏
- @property(nonatomic,strong)NSString *filePath;
- @property(nonatomic,assign)ActionType actionType;
- @property(nonatomic,strong)NSString *waterVideoPath;
- @end
- @implementation TCVideoEditViewController {
- TXVideoEditer *_ugcEdit;
- TCVideoPreview *_videoPreview;
-
- unsigned long long _fileSize;
- NSMutableArray *_cutPathList;
- NSString *_videoOutputPath;
-
- UIProgressView *_playProgressView;
- UILabel *_startTimeLabel;
- UILabel *_endTimeLabel;
- CGFloat _leftTime;
- CGFloat _rightTime;
- int _effectType;
- BOOL _isReverse;
- CGFloat _playTime;
- TimeType _timeType;
-
- BOOL _isRecordBg; //是否是录制开始设置的背景音乐(改收费版SDK添加)
- UIImage *watermark;
- BOOL isUploadWater;
- CGFloat _originVolume; //记录系统音量
- MPVolumeView *_volumeView;
- UISlider *_volumeViewSlider;
- BOOL _changeVolume;
- }
- static int MIXBTN_W = 55;
- -(void)creatVoluem {
- if (_volumeViewSlider == nil) {
- _volumeView = [[MPVolumeView alloc] initWithFrame:CGRectMake(-100, -100, 40, 40)];
- [self.view addSubview:_volumeView];
- for (UIView* newView in _volumeView.subviews) {
- if ([newView.class.description isEqualToString:@"MPVolumeSlider"]){
- _volumeViewSlider = (UISlider*)newView;
- break;
- }
- }
- }
- [_volumeView setHidden:NO];
- [_volumeView setShowsRouteButton:YES];
- [_volumeView setShowsVolumeSlider:YES];
- }
- -(void)recoveryVolume{
- if (_changeVolume) {
- _changeVolume = NO;
- _volumeViewSlider.value = _originVolume ;
- }
- }
- #pragma mark - get/set
- -(UIButton *)backBtn {
- if (!_backBtn) {
- _backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _backBtn.frame = CGRectMake(10, 40, 40, 40);
- [_backBtn setImage:[UIImage imageNamed:@"pub_back"] forState:0];
- [_backBtn addTarget:self action:@selector(clickBackBtn) forControlEvents:UIControlEventTouchUpInside];
- }
- return _backBtn;
- }
- - (UIButton *)selVolumeBtn {
- if (!_selVolumeBtn) {
- _selVolumeBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _selVolumeBtn.frame = CGRectMake(_window_width-MIXBTN_W*2-8-12, 40, MIXBTN_W, MIXBTN_W);
- [_selVolumeBtn setImage:[UIImage imageNamed:@"音量"] forState:0];
- [_selVolumeBtn setTitle:YZMsg(@"音量") forState:0];
- _selVolumeBtn.titleLabel.font = SYS_Font(13);
- [_selVolumeBtn addTarget:self action:@selector(clickSelVolumeBtn) forControlEvents:UIControlEventTouchUpInside];
- _selVolumeBtn = [PublicObj setUpImgDownText:_selVolumeBtn];
- }
- return _selVolumeBtn;
- }
- - (UIButton *)selMusicBtn {
- if (!_selMusicBtn) {
- _selMusicBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _selMusicBtn.frame = CGRectMake(_window_width-MIXBTN_W-8-12, 40, MIXBTN_W+12, MIXBTN_W);
- [_selMusicBtn setImage:[UIImage imageNamed:@"音乐"] forState:0];
- [_selMusicBtn setTitle:YZMsg(@"选音乐") forState:0];
- _selMusicBtn.titleLabel.font = SYS_Font(13);
- [_selMusicBtn addTarget:self action:@selector(clickMusicBtn) forControlEvents:UIControlEventTouchUpInside];
- _selMusicBtn = [PublicObj setUpImgDownText:_selMusicBtn];
- }
- return _selMusicBtn;
- }
- -(UIView *)botBtnMix{
- if (!_botBtnMix) {
- _botBtnMix = [[UIView alloc]initWithFrame:CGRectMake(0,_window_height-80-ShowDiff, _window_width, 80+ShowDiff)];
- _botBtnMix.backgroundColor = [UIColor clearColor];
-
- //特效
- _effectBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _effectBtn.frame = CGRectMake(8, 0, MIXBTN_W, MIXBTN_W);
- [_effectBtn setImage:[UIImage imageNamed:@"特效"] forState:0];
- [_effectBtn setTitle:YZMsg(@"特效") forState:0];
- _effectBtn.titleLabel.font = SYS_Font(13);
- [_effectBtn addTarget:self action:@selector(clickEffectBtn) forControlEvents:UIControlEventTouchUpInside];
- _effectBtn = [PublicObj setUpImgDownText:_effectBtn];
- [_botBtnMix addSubview:_effectBtn];
-
- //封面(隐藏了 CGRectMake(_effectBtn.right+3, 0, MIXBTN_W, MIXBTN_W);)
- _coverBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _coverBtn.frame = CGRectMake(_effectBtn.right+3, 0, 0, 0);
- [_coverBtn setImage:[UIImage imageNamed:@"封面"] forState:0];
- [_coverBtn setTitle:YZMsg(@"封面") forState:0];
- _coverBtn.titleLabel.font = SYS_Font(13);
- [_coverBtn addTarget:self action:@selector(clickCovertBtn) forControlEvents:UIControlEventTouchUpInside];
- _coverBtn = [PublicObj setUpImgDownText:_coverBtn];
- [_botBtnMix addSubview:_coverBtn];
- _coverBtn.hidden = YES;
-
- //滤镜
- _filterfBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _filterfBtn.frame = CGRectMake(_coverBtn.right+3, 0, MIXBTN_W, MIXBTN_W);
- [_filterfBtn setImage:[UIImage imageNamed:@"滤镜"] forState:0];
- [_filterfBtn setTitle:YZMsg(@"滤镜") forState:0];
- _filterfBtn.titleLabel.font = SYS_Font(13);
- [_filterfBtn addTarget:self action:@selector(clickFilterBtn) forControlEvents:UIControlEventTouchUpInside];
- _filterfBtn = [PublicObj setUpImgDownText:_filterfBtn];
- [_botBtnMix addSubview:_filterfBtn];
-
- //下一步
- _nextBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- _nextBtn.frame = CGRectMake(_window_width-10-65, 12.5, 65, 30);
- [_nextBtn setTitle:YZMsg(@"下一步") forState:0];
- _nextBtn.titleLabel.font = SYS_Font(14);
- [_nextBtn setTitleColor:[UIColor whiteColor] forState:0];
- _nextBtn.backgroundColor = Pink_Cor;
- _nextBtn.layer.masksToBounds = YES;
- _nextBtn.layer.cornerRadius = 15;
- [_nextBtn addTarget:self action:@selector(clickNextBtn) forControlEvents:UIControlEventTouchUpInside];
- [_botBtnMix addSubview:_nextBtn];
-
- }
- return _botBtnMix;
- }
- -(UIView *)botFunctionMix {
- if (!_botFunctionMix) {
- CGFloat botFunH = _window_height/2;
- _botFunctionMix = [[UIView alloc]initWithFrame:CGRectMake(0, _window_height-botFunH-ShowDiff, _window_width, botFunH+ShowDiff)];
- _botFunctionMix.backgroundColor = [UIColor clearColor];
-
- //底部bar
- _bottomBar = [[TCBottomTabBar alloc] initWithFrame:CGRectMake(0, botFunH - 40 * kScaleY, _window_width, 40 * kScaleY+ShowDiff)];
- _bottomBar.delegate = self;
- [_botFunctionMix addSubview:_bottomBar];
-
- CGFloat selectViewHeight = _window_height >= 667 ? 120 * kScaleY : 120 * kScaleY;
-
- UIView *alphaV = [[UIView alloc]initWithFrame:CGRectMake(0, _bottomBar.top-selectViewHeight, _window_width, selectViewHeight)];
- alphaV.backgroundColor = [UIColor blackColor];
- alphaV.alpha = 0.4;
- [_botFunctionMix addSubview:alphaV];
-
- _cutTipsLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, _bottomBar.top - selectViewHeight, _window_width, selectViewHeight)];
- _cutTipsLabel.textAlignment = NSTextAlignmentCenter;
- _cutTipsLabel.text = YZMsg(@"请拖拽两侧滑块选择裁剪区域");
- _cutTipsLabel.textColor = [UIColor whiteColor];
- _cutTipsLabel.font = [UIFont systemFontOfSize:16];
- [_cutTipsLabel setAdjustsFontSizeToFitWidth:YES];
- [_botFunctionMix addSubview:_cutTipsLabel];
-
- _videoCutView = [[TCVideoCutView alloc] initWithFrame:CGRectMake(0,40, _window_width, botFunH-_bottomBar.height-selectViewHeight-40) videoPath:_videoPath videoAssert:_videoAsset];
- _videoCutView.delegate = self;
- //_videoCutView.backgroundColor = [UIColor grayColor];
- [_botFunctionMix addSubview:_videoCutView];
-
- _timeSelectView = [[TimeSelectView alloc] initWithFrame:CGRectMake(0, _bottomBar.top - selectViewHeight, _window_width, selectViewHeight)];
- //_timeSelectView.backgroundColor = [UIColor yellowColor];
- _timeSelectView.delegate = self;
- _timeSelectView.isAlbum = _isAlbum;
-
- _effectSelectView = [[EffectSelectView alloc] initWithFrame:_timeSelectView.frame];
- //_effectSelectView.backgroundColor = [UIColor greenColor];
- _effectSelectView.delegate = self;
-
- }
- return _botFunctionMix;
- }
- - (TCMusicMixView *)musixMixView {
- if (!_musixMixView) {
- //haveBGM这里初始值一旦为YES“原声”再不可编辑
- _musixMixView = [[TCMusicMixView alloc] initWithFrame:CGRectMake(0, _window_height-ShowDiff-215, _window_width, 215+ShowDiff)haveBgm:_haveBGM];
- _musixMixView.delegate = self;
- _musixMixView.backgroundColor = [UIColor clearColor];
- }
- return _musixMixView;
- }
- -(TCFilterSettingView *)filterView {
- if (!_filterView) {
- _filterView = [[TCFilterSettingView alloc] initWithFrame:CGRectMake(0, _window_height-ShowDiff-90, _window_width, 90+ShowDiff)];
- _filterView.delegate = self;
- }
- return _filterView;
- }
- #pragma mark - 按钮点击事件
- -(void)showBotBtnMix{
- _musixMixView.hidden = YES;
- _botFunctionMix.hidden = YES;
- _filterView.hidden = YES;
- _botBtnMix.hidden = NO;
- }
- - (void) touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
- if (_botFunctionMix.hidden == NO ||_filterView.hidden == NO ||_musixMixView.hidden == NO) {
- UITouch *touch = [[event allTouches] anyObject];
- CGPoint _touchPoint = [touch locationInView:self.view];
- if (YES == CGRectContainsPoint(CGRectMake(0, 64, _window_width, _window_height*2/3), _touchPoint)) {
- [self showBotBtnMix];
- }
- }else{
- //视频暂停
- [_videoPreview setPlayBtn:_videoPreview.isPlaying];
- [_videoPreview playVideo];
- }
- }
- -(void)clickBackBtn {
- //[_ugcEdit setBGM:nil result:nil];
-
- YBWeakSelf;
- NSDictionary *contentDic = @{@"title":YZMsg(@"提示"),@"msg":YZMsg(@"是否退出视频编辑"),@"left":YZMsg(@"取消"),@"right":YZMsg(@"确定")};
- [YBAlertView showAlertView:contentDic complete:^(int eventType) {
- if (eventType == 1) {
- [weakSelf sureExit];
- }
- }];
-
- }
- -(void)sureExit {
- [self recoveryVolume];
- [self pauseBack];
- //[self.navigationController popToRootViewControllerAnimated:YES];
- if (_isTakeSame == YES) {
- //拍同款返回到同款音乐视频列表
- BOOL findVC = NO;
- for (UIViewController *forVC in self.navigationController.childViewControllers) {
- if ([forVC isKindOfClass:[YBTakeSameVideoVC class]]) {
- findVC = YES;
- [self.navigationController popToViewController:forVC animated:YES];
- break;
- }
- }
- if (findVC == NO) {
- [self.navigationController popToRootViewControllerAnimated:YES];
- }
- }else if (![PublicObj checkNull:[YBActiveManager shareManager].activeId]){
- if ([YBActiveManager shareManager].startVC) {
- YBBaseViewController *gobackVC = [YBActiveManager shareManager].startVC;
- [self.navigationController popToViewController:gobackVC animated:YES];
- [[YBActiveManager shareManager] resetActive];
- }else {
- [self.navigationController popToRootViewControllerAnimated:YES];
- }
- }else {
- [self.navigationController popToRootViewControllerAnimated:YES];
- }
- }
- -(void)clickSelVolumeBtn {
-
- [self showBotBtnMix];
-
- //选择音量-剪辑音乐
- [self cutMusic];
-
- }
- -(void)clickMusicBtn {
- //暂停播放
- [self onVideoPause];
- [self showBotBtnMix];
-
- //更改音乐
- YBVideoMusicView *mVC = [[YBVideoMusicView alloc]init];
- mVC.fromWhere = @"edit";
- __weak TCVideoEditViewController *weakSelf = self;
- mVC.pathEvent = ^(NSString *event, NSString *musicID) {
- weakSelf.musicPath = event;
- weakSelf.musicID = musicID;
- //删除时editView隐藏重新选择后显示
- weakSelf.musixMixView.editView.hidden = NO;
- //重新选择后_filePath 不再是delate状态将其置空
- weakSelf.filePath = nil;
- [self cutMusic];
- };
- YBNavigationController *nav = [[YBNavigationController alloc]initWithRootViewController:mVC];
- nav.modalPresentationStyle = 0;
- [self presentViewController:nav animated:YES completion:nil];
-
- }
- -(void)clickEffectBtn {
- //特效-展示botbar
- self.botFunctionMix.hidden = NO;
- self.botBtnMix.hidden = YES;
-
- }
- -(void)clickCovertBtn {
- //封面
- [MBProgressHUD showPop:YZMsg(@"敬请期待")];
- }
- -(void)clickFilterBtn {
- //滤镜
- self.filterView.hidden = NO;
- self.botBtnMix.hidden = YES;
- }
- -(void)clickNextBtn {
- //下一步
- [self pause];
- // if (_fileSize > 200 * 1024 * 1024) {
- // [MBProgressHUD showPop:@"视频文件过大,超过200M!"];
- // return;
- // }
- YBWeakSelf;
- RKActionSheet *sheet = [[RKActionSheet alloc]initWithTitle:@""];
- [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"仅发布") complete:^{
- weakSelf.actionType = ActionType_Publish;
- [weakSelf clickEvent];
- }];
- [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"仅保存") complete:^{
- weakSelf.actionType = ActionType_Save;
- [weakSelf clickEvent];
- }];
- [sheet addActionWithType:RKSheet_Default andTitle:YZMsg(@"保存并发布") complete:^{
- weakSelf.actionType = ActionType_Save_Publish;
- [weakSelf clickEvent];
- }];
- [sheet addActionWithType:RKSheet_Cancle andTitle:YZMsg(@"取消") complete:^{
- }];
- [sheet showSheet];
-
-
- }
- -(void)clickEvent {
- YBWeakSelf;
- [[YBProgressObj progressManeger]setUpViewCancelHidden:NO andComplete:^{
- [weakSelf onGenerateCancelBtnClicked:nil];
- }];
- [YBProgressObj progressManeger].generationHidden = NO;
-
- [_ugcEdit setCutFromTime:_leftTime toTime:_rightTime];
- [self checkVideoOutputPath];
- //VIDEO_COMPRESSED_540P
- [_ugcEdit generateVideo:VIDEO_COMPRESSED_720P videoOutputPath:_videoOutputPath];
- [self onVideoPause];
- [_videoPreview setPlayBtn:NO];
- }
- - (void)checkVideoOutputPath{
- NSFileManager *manager = [[NSFileManager alloc] init];
- if ([manager fileExistsAtPath:_videoOutputPath]) {
- BOOL success = [manager removeItemAtPath:_videoOutputPath error:nil];
- if (success) {
- NSLog(@"Already exist. Removed!");
- }
- }
- }
- -(void)didReceiveMemoryWarning {
- [super didReceiveMemoryWarning];
- NSLog(@"rk20200118===编辑====内存内存内存=======");
-
- //[MBProgressHUD showError:@"TC Memory"];
-
- }
- //返回、音量、音乐保持最前面
- -(void)keepViewFront{
- [self.view bringSubviewToFront:self.backBtn];
- [self.view bringSubviewToFront:self.selVolumeBtn];
- [self.view bringSubviewToFront:self.selMusicBtn];
- }
- -(instancetype)init {
- self = [super init];
- if (self) {
- _cutPathList = [NSMutableArray array];
- _videoOutputPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"outputCut.mp4"];
- _waterVideoPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"outputCut_water.mp4"];
- _effectType = -1;
- // _videoTextInfos = [NSMutableArray new];
- [self getWaterImage];
- }
- return self;
- }
- - (void)getWaterImage{
- NSString *waterUrl = [[NSUserDefaults standardUserDefaults] objectForKey:@"watermarklogo"];
- [[SDWebImageDownloader sharedDownloader] downloadImageWithURL:[NSURL URLWithString:waterUrl] options:0 progress:nil completed:^(UIImage *image, NSData *data, NSError *error, BOOL finished) {
- watermark = image;
- }];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
-
- [UIApplication sharedApplication].statusBarHidden = YES;
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
-
- [UIApplication sharedApplication].statusBarHidden = NO;
- }
- - (void)viewDidDisappear:(BOOL)animated {
- [super viewDidDisappear:animated];
- }
- - (void)dealloc {
-
- [_videoPreview removeNotification];
- _videoPreview = nil;
-
- NSLog(@"rk20200118===编辑===dealloc");
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- [self creatVoluem];
- self.naviView.hidden = YES;
- self.navigationController.interactivePopGestureRecognizer.enabled = NO;
- self.navigationController.interactivePopGestureRecognizer.delegate =nil;
-
- self.view.backgroundColor = UIColor.blackColor;
- self.navigationController.navigationBarHidden = YES;
- _isRecordBg = _haveBGM;
- if (_videoAsset == nil && _videoPath != nil) {
- NSURL *avUrl = [NSURL fileURLWithPath:_videoPath];
- _videoAsset = [AVAsset assetWithURL:avUrl];
- }
-
- //返回、音量、音乐
- [self.view addSubview:self.backBtn];
- [self.view addSubview:self.selVolumeBtn];
- [self.view addSubview:self.selMusicBtn];
- if (_recordType == RecordType_Chorus) {
- _selVolumeBtn.hidden = _selMusicBtn.hidden = YES;
- }
-
- _videoPreview = [[TCVideoPreview alloc] initWithFrame:CGRectMake(0, 0, _window_width, _window_height) coverImage:nil];
- _videoPreview.delegate = self;
- [self.view addSubview:_videoPreview];
-
- _playProgressView = [[UIProgressView alloc] initWithFrame:CGRectMake(0, _videoPreview.top+2, _window_width, 6)];
- _playProgressView.trackTintColor = UIColorFromRGB(0xd8d8d8);
- _playProgressView.progressTintColor = Pink_Cor;//UIColorFromRGB(0x0accac);
- [self.view addSubview:_playProgressView];
-
- //保持view-btn不被遮挡
- [self keepViewFront];
-
- //底部按钮区域
- [self.view addSubview:self.botBtnMix];
- //底部功能区域
- [self.view addSubview:self.botFunctionMix];
- self.botFunctionMix.hidden = YES;
- //滤镜种类
- [self.view addSubview:self.filterView];
- self.filterView.hidden = YES;
- //音乐剪辑
- [self.view addSubview:self.musixMixView];
- self.musixMixView.hidden = YES;
-
- TXPreviewParam *param = [[TXPreviewParam alloc] init];
- param.videoView = _videoPreview.renderView;
-
- if (IS_IPHONE_X && _recordType != RecordType_Chorus ){
- if(!_isAlbum){
- param.renderMode = PREVIEW_RENDER_MODE_FILL_SCREEN;
- }else{
- param.renderMode = PREVIEW_RENDER_MODE_FILL_EDGE;
- }
- }else{
- param.renderMode = PREVIEW_RENDER_MODE_FILL_EDGE;
- }
-
- _ugcEdit = [[TXVideoEditer alloc] initWithPreview:param];
- _ugcEdit.generateDelegate = self;
- _ugcEdit.previewDelegate = _videoPreview;
-
- [_ugcEdit setVideoAsset:_videoAsset];
- TXVideoInfo *videoMsg = [TXVideoInfoReader getVideoInfoWithAsset:_videoAsset];
- _fileSize = videoMsg.fileSize;
- CGFloat duration = videoMsg.duration;
- _rightTime = duration;
- _endTimeLabel.text = [NSString stringWithFormat:@"%d:%02d", (int)duration / 60, (int)duration % 60];
-
- if (_isTakeSame) {
- //拍同款选择的 转场、本地视频要加一下音乐
- _musixMixView.editView.hidden = NO;
- _filePath = nil;
- [self cutMusic];
- self.musixMixView.hidden = YES;
- self.botBtnMix.hidden = NO;
- }
- }
- - (void)viewDidAppear:(BOOL)animated {
- [super viewDidAppear:animated];
- if ([PublicObj getSysOutputVolume] < 0.2) {
- _changeVolume = YES;
- _originVolume = [AVAudioSession sharedInstance].outputVolume;
- _volumeViewSlider.value = 0.3;
- }
- [_videoPreview setPlayBtn:NO];
- [_videoPreview playVideo];
- }
- //- (void)goBack {
- // [_ugcEdit setBGM:nil result:nil];
- // [self pause];
- // [self.navigationController popViewControllerAnimated:YES];
- //
- //}
- //rk-1-16
- - (void)pauseBack{
- [_ugcEdit setBGM:nil result:nil];
- [_ugcEdit pausePlay];
- [_videoPreview setPlayBtn:NO];
- [_ugcEdit stopPlay];
- _ugcEdit.generateDelegate = nil;
- _ugcEdit = nil;
- [_videoPreview removeNotification];
- [_videoPreview removeFromSuperview];
- _videoPreview = nil;
- }
- - (void)pause {
- [_ugcEdit stopPlay];
- [_videoPreview setPlayBtn:NO];
- }
- - (void)onGenerateCancelBtnClicked:(UIButton*)sender {
- isUploadWater = NO;
- [_ugcEdit cancelGenerate];
- [self destoryProgressView];
- }
- -(void)destoryProgressView {
- [YBProgressObj progressManeger].generationHidden = YES;
- [[YBProgressObj progressManeger] progressDestroy];
- }
- #pragma mark FilterSettingViewDelegate
- - (void)onSetFilterWithImage:(UIImage *)image {
- [_ugcEdit setFilter:image];
- }
- #pragma mark - BottomTabBarDelegate
- - (void)onCutBtnClicked {
- //[self pause];
-
- [_timeSelectView removeFromSuperview];
- [_effectSelectView removeFromSuperview];
- [_botFunctionMix addSubview:_videoCutView];
- [_botFunctionMix addSubview:_cutTipsLabel];
- [_videoCutView setEffectDeleteBtnHidden:YES];
-
- }
- - (void)onFilterBtnClicked {
- //[self pause];
- [_videoCutView removeFromSuperview];
- [_musixMixView removeFromSuperview];
- [_cutTipsLabel removeFromSuperview];
- [_timeSelectView removeFromSuperview];
- [_effectSelectView removeFromSuperview];
-
- [_botFunctionMix addSubview:_filterView];
- _videoCutView.videoRangeSlider.hidden = NO;
-
- }
- - (void)onMusicBtnClicked {
- //[self pause];
- [_filterView removeFromSuperview];
- [_videoCutView removeFromSuperview];
- [_cutTipsLabel removeFromSuperview];
- [_timeSelectView removeFromSuperview];
- [_effectSelectView removeFromSuperview];
-
- [_botFunctionMix addSubview:_musixMixView];
- _videoCutView.videoRangeSlider.hidden = NO;
-
-
- }
- - (void)onTextBtnClicked {
- //[self pause];
- [_filterView removeFromSuperview];
- [_videoCutView removeFromSuperview];
- [_musixMixView removeFromSuperview];
- [_cutTipsLabel removeFromSuperview];
- [_timeSelectView removeFromSuperview];
- [_effectSelectView removeFromSuperview];
-
- _videoCutView.videoRangeSlider.hidden = NO;
-
- }
- - (void)onEffectBtnClicked {
-
- [_cutTipsLabel removeFromSuperview];
- [_timeSelectView removeFromSuperview];
-
- [_botFunctionMix addSubview:_videoCutView];
- [_botFunctionMix addSubview:_effectSelectView];
- [_videoCutView setEffectDeleteBtnHidden:NO];
- }
- -(void)onTimeBtnClicked {
-
- [_effectSelectView removeFromSuperview];
- [_cutTipsLabel removeFromSuperview];
-
- [_botFunctionMix addSubview:_videoCutView];
- [_botFunctionMix addSubview:_timeSelectView];
- [_videoCutView setEffectDeleteBtnHidden:YES];
- }
- #pragma mark TXVideoGenerateListener
- -(void) onGenerateProgress:(float)progress {
- //[MBProgressHUD HUDForView:self.view].progress = progress;
- if (watermark) {
- if (isUploadWater && _actionType != ActionType_Save) {
- [YBProgressObj progressManeger].generationProgress = progress/2 + 0.5;
- }else{
- [YBProgressObj progressManeger].generationProgress = progress/2;
- }
- }else{
- [YBProgressObj progressManeger].generationProgress = progress;
- }
-
- NSLog(@"==正在合成:%f",progress);
- }
- -(void) onGenerateComplete:(TXGenerateResult *)result {
-
- if (result.retCode == 0) {
- if (_actionType == ActionType_Save_Publish) {
- if (watermark) {
- if (isUploadWater) {
- [self destoryProgressView];
- UISaveVideoAtPathToSavedPhotosAlbum(_videoOutputPath, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
- }else{
- isUploadWater = YES;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [_ugcEdit setWaterMark:watermark normalizationFrame:CGRectMake(0.03, 0.04, 0.25, 0)];
- [_ugcEdit generateVideo:VIDEO_COMPRESSED_720P videoOutputPath:_waterVideoPath];
- });
- }
- }else{
- [self destoryProgressView];
- UISaveVideoAtPathToSavedPhotosAlbum(_videoOutputPath, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
- }
- }else if (_actionType == ActionType_Save){
- [self destoryProgressView];
- UISaveVideoAtPathToSavedPhotosAlbum(_videoOutputPath, self, @selector(video:didFinishSavingWithError:contextInfo:), nil);
- }
- else if (_actionType == ActionType_Publish){
- if (isUploadWater) {
- [self destoryProgressView];
- [self publish:_waterVideoPath];
- }else{
-
- if (watermark) {
- isUploadWater = YES;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- [_ugcEdit setWaterMark:watermark normalizationFrame:CGRectMake(0.03, 0.04, 0.25, 0)];
- [_ugcEdit generateVideo:VIDEO_COMPRESSED_720P videoOutputPath:_waterVideoPath];
- });
- }else{
- [self destoryProgressView];
- [self publish:nil];
- }
- }
- }
- }else{
- [self destoryProgressView];
-
- NSDictionary *contentDic = @{@"title":YZMsg(@"视频生成失败"),@"msg":[NSString stringWithFormat:@"%@:%ld %@:%@",YZMsg(@"错误码"),(long)result.retCode,YZMsg(@"错误信息"),result.descMsg],@"left":@"",@"right":YZMsg(@"确定")};
- [YBAlertView showAlertView:contentDic complete:^(int eventType) {
-
- }];
- }
- }
- - (void)video:(NSString *)videoPath didFinishSavingWithError:(NSError *)error contextInfo:(void *)contextInfo {
-
- if (_actionType == ActionType_Save) {
- //[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
- [MBProgressHUD showPop:YZMsg(@"保存成功")];
- [self pauseBack];
- /*
- for (UIViewController *subVC in [[[[UIApplication sharedApplication].delegate window] rootViewController] childViewControllers]) {
- if ([subVC isKindOfClass:[YBVideoMusicView class]]) {
- [self dismissViewControllerAnimated:NO completion:^{
- [subVC.navigationController popToRootViewControllerAnimated:NO];
- }];
- }
- }
- */
- [self.navigationController popToRootViewControllerAnimated:YES];
- return;
- }
- if (isUploadWater) {
- [self publish:_waterVideoPath];
- }else{
- [self publish:nil];
-
- }
- }
- - (void)publish:(NSString *)waterPath {
- [self recoveryVolume];
- isUploadWater = NO;
- //[MBProgressHUD hideAllHUDsForView:self.view animated:YES];
- //TXVideoInfo *videoMsg = [TXUGCVideoInfoReader getVideoInfo:_videoOutputPath];
- [UIApplication sharedApplication].statusBarHidden = NO;
- dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
- TCVideoPublishController *vc = [[TCVideoPublishController alloc] initWithPath:_videoOutputPath
- videoMsg:[TXVideoInfoReader getVideoInfo:_videoOutputPath]];
- vc.musicID = _musicID;
- vc.waterVideoPath = waterPath;
- vc.isTakeSame = _isTakeSame;
- vc.videoAsset = _videoAsset;
- [self.navigationController pushViewController:vc animated:YES];
- [self pauseBack];
- });
- }
- #pragma mark TCVideoPreviewDelegate
- - (void)onVideoPlay {
- CGFloat currentPos = _videoCutView.videoRangeSlider.currentPos;
- if (currentPos < _leftTime || currentPos > _rightTime)
- currentPos = _leftTime;
-
- if(_isReverse && currentPos != 0){
- [_ugcEdit startPlayFromTime:0 toTime:currentPos];
- }
- else if(_videoCutView.videoRangeSlider.rightPos != 0){
- [_ugcEdit startPlayFromTime:currentPos toTime:_videoCutView.videoRangeSlider.rightPos];
- }
- else{
- [_ugcEdit startPlayFromTime:currentPos toTime:_rightTime];
- }
- }
- - (void)onVideoPause {
- [_ugcEdit pausePlay];
- }
- - (void)onVideoResume {
- //[_ugcEdit resumePlay];
- [self onVideoPlay];
- }
- - (void)onVideoPlayProgress:(CGFloat)time {
- _playTime = time;
-
- _playProgressView.progress = (time - _leftTime) / (_rightTime - _leftTime);
- [_videoCutView setPlayTime:time];
-
- }
- - (void)onVideoPlayFinished {
- if (_effectType != -1) {
- [self onVideoEffectEndClick:_effectType];
- }else{
- [_ugcEdit startPlayFromTime:_leftTime toTime:_rightTime];
- }
- }
- - (void)onVideoEnterBackground {
- //[MBProgressHUD hideHUDForView:self.view animated:YES];
- [self onVideoPause];
-
- //视频生成中不能进后台,因为使用硬编,会导致失败
- if ([YBProgressObj progressManeger].isExist) {
- [self destoryProgressView];
- [_ugcEdit cancelGenerate];
-
- NSDictionary *contentDic = @{@"title":YZMsg(@"视频生成失败"),@"msg":YZMsg(@"中途切后台或则被电话,闹钟等打断导致,请重新生成"),@"left":@"",@"right":YZMsg(@"确定")};
- [YBAlertView showAlertView:contentDic complete:^(int eventType) {
-
- }];
-
-
- }
- }
- #pragma mark - MusicMixViewDelegate
- -(void)cutMusic{
- //当首次进入这里并且没有选择音乐的时候前两个条件就不能满足要求了,这时要加第三个条件(_musicPath.length > 0)
- if (![_musicPath isEqual:_filePath] && ![_filePath isEqual:@"delate"] && _musicPath.length > 0) {
- NSFileManager *managers=[NSFileManager defaultManager];
- NSArray *subArray = [_musicPath componentsSeparatedByString:@"*"];
- NSString *musicNameStr = [subArray objectAtIndex:1];
- NSString *singerStr = [subArray objectAtIndex:2];
- /*
- NSString *timeStr = [subArray objectAtIndex:3];
- NSString *songID = [subArray objectAtIndex:4];
- NSArray *IDArray = [songID componentsSeparatedByString:@"."];
- songID = [IDArray objectAtIndex:0];
- */
- TCMusicInfo* musicInfo = [TCMusicInfo new];
- NSURL *url = [NSURL fileURLWithPath:_musicPath];
- AVURLAsset *musicAsset = [AVURLAsset URLAssetWithURL:url options:nil];
- musicInfo.duration = musicAsset.duration.value / musicAsset.duration.timescale;
- musicInfo.filePath = _musicPath;
- musicInfo.soneName = musicNameStr;
- musicInfo.singerName = singerStr;
- __weak TCVideoEditViewController *weakSelf = self;
- if ([managers fileExistsAtPath:_musicPath]) {
- dispatch_async(dispatch_get_main_queue(), ^{
- weakSelf.musixMixView.editView.hidden = NO;
- [self saveAssetURLToFile:musicInfo assetURL:url];
- });
- }
- }
- self.musixMixView.hidden = NO;
- self.botBtnMix.hidden = YES;
-
- }
- - (void)onSetVideoVolume:(CGFloat)videoVolume musicVolume:(CGFloat)musicVolume {
- [_ugcEdit setVideoVolume:videoVolume];
- [_ugcEdit setBGMVolume:musicVolume];
- }
- - (void)onSetBGMWithFilePath:(NSString *)filePath startTime:(CGFloat)startTime endTime:(CGFloat)endTime {
- if (![_filePath isEqualToString:filePath]) {
- __weak __typeof(self) weakSelf = self;
- [_ugcEdit setBGM:filePath result:^(int result) {
- dispatch_async(dispatch_get_main_queue(), ^{
- if (result == -1){
- NSDictionary *contentDic = @{@"title":YZMsg(@"设置背景音乐失败"),@"msg":YZMsg(@"不支持当前格式的背景音乐!"),@"left":@"",@"right":YZMsg(@"确定")};
- [YBAlertView showAlertView:contentDic complete:^(int eventType) {
- }];
- }else{
- [weakSelf setBGMVolume:filePath startTime:startTime endTime:endTime];
- }
- });
- }];
- }else{
- [self setBGMVolume:filePath startTime:startTime endTime:endTime];
- }
-
- }
- - (void)delBGM {
- _musicID = @"";
- _musicPath = @"";
- _haveBGM = NO;
-
- YBWeakSelf;
- [_ugcEdit setBGM:nil result:^(int result) {
- NSLog(@"del:%d",result);
- dispatch_async(dispatch_get_main_queue(), ^{
- [weakSelf setBGMVolume:nil startTime:0 endTime:0];
- });
- }];
-
- }
- -(void)setBGMVolume:(NSString *)filePath startTime:(CGFloat)startTime endTime:(CGFloat)endTime {
- _filePath = filePath;
- [_ugcEdit setBGMStartTime:startTime endTime:endTime];
- if (_filePath == nil && _isRecordBg==NO) {
- CGFloat bgVolume = ([PublicObj getSysOutputVolume] < 0.2 )? 0.3 : [PublicObj getSysOutputVolume];
- [_ugcEdit setVideoVolume:bgVolume];
- }
-
- [_ugcEdit startPlayFromTime:_leftTime toTime:_rightTime];
- [_ugcEdit setBGMLoop:YES];
- [_videoPreview setPlayBtn:YES];
- }
- #pragma mark - VideoCutViewDelegate
- - (void)onVideoLeftCutChanged:(TCVideoRangeSlider *)sender {
- //[_ugcEdit pausePlay];
- [_videoPreview setPlayBtn:NO];
- [_ugcEdit previewAtTime:sender.leftPos];
- }
- - (void)onVideoRightCutChanged:(TCVideoRangeSlider *)sender {
- [_videoPreview setPlayBtn:NO];
- [_ugcEdit previewAtTime:sender.rightPos];
- }
- - (void)onVideoCutChangedEnd:(TCVideoRangeSlider *)sender {
- _leftTime = sender.leftPos;
- _rightTime = sender.rightPos;
- _startTimeLabel.text = [NSString stringWithFormat:@"%d:%02d", (int)sender.leftPos / 60, (int)sender.leftPos % 60];
- _endTimeLabel.text = [NSString stringWithFormat:@"%d:%02d", (int)sender.rightPos / 60, (int)sender.rightPos % 60];
- [_ugcEdit startPlayFromTime:sender.leftPos toTime:sender.rightPos];
- [_videoPreview setPlayBtn:YES];
- }
- - (void)onVideoCenterRepeatChanged:(TCVideoRangeSlider*)sender {
- [_videoPreview setPlayBtn:NO];
- [_ugcEdit previewAtTime:sender.centerPos];
- }
- - (void)onVideoCenterRepeatEnd:(TCVideoRangeSlider*)sender {
- _leftTime = sender.leftPos;
- _rightTime = sender.rightPos;
-
- if (_timeType == TimeType_Repeat) {
- TXRepeat *repeat = [[TXRepeat alloc] init];
- repeat.startTime = sender.centerPos;
- repeat.endTime = sender.centerPos + 0.5;
- repeat.repeatTimes = 3;
- [_ugcEdit setRepeatPlay:@[repeat]];
- [_ugcEdit setSpeedList:nil];
- }
- else if (_timeType == TimeType_Speed) {
- TXSpeed *speed = [[TXSpeed alloc] init];
- speed.startTime = sender.centerPos;
- speed.endTime = sender.rightPos;
- speed.speedLevel = SPEED_LEVEL_SLOW;
- [_ugcEdit setSpeedList:@[speed]];
- [_ugcEdit setRepeatPlay:nil];
- }
-
- if (_isReverse) {
- [_ugcEdit startPlayFromTime:sender.leftPos toTime:sender.centerPos + 1.5];
- }else{
- [_ugcEdit startPlayFromTime:sender.centerPos toTime:sender.rightPos];
- }
- [_videoPreview setPlayBtn:YES];
- }
- - (void)onVideoCutChange:(TCVideoRangeSlider *)sender seekToPos:(CGFloat)pos {
- _playTime = pos;
-
- [_ugcEdit previewAtTime:pos];
- [_videoPreview setPlayBtn:NO];
- _playProgressView.progress = (pos - _leftTime) / (_rightTime - _leftTime);
- }
- //- (void)onSetSpeedUp:(BOOL)isSpeedUp
- //{
- // if (isSpeedUp) {
- // [_ugcEdit setSpeedLevel:2.0];
- // } else {
- // [_ugcEdit setSpeedLevel:1.0];
- // }
- //}
- //- (void)onSetSpeedUpLevel:(CGFloat)level
- //{
- // [_ugcEdit setSpeedLevel:level];
- //}
- - (void)onSetBeautyDepth:(float)beautyDepth WhiteningDepth:(float)whiteningDepth {
- [_ugcEdit setBeautyFilter:beautyDepth setWhiteningLevel:whiteningDepth];
- }
- - (void)onEffectDelete {
- [_ugcEdit deleteLastEffect];
- }
- #pragma mark - MPMediaPickerControllerDelegate
- - (void)mediaPicker:(MPMediaPickerController *)mediaPicker didPickMediaItems:(MPMediaItemCollection *)mediaItemCollection {
- NSArray *items = mediaItemCollection.items;
- MPMediaItem *songItem = [items objectAtIndex:0];
-
- NSURL *url = [songItem valueForProperty:MPMediaItemPropertyAssetURL];
- NSString* songName = [songItem valueForProperty: MPMediaItemPropertyTitle];
- NSString* authorName = [songItem valueForProperty:MPMediaItemPropertyArtist];
- NSNumber* duration = [songItem valueForKey:MPMediaItemPropertyPlaybackDuration];
- NSLog(@"MPMediaItemPropertyAssetURL = %@", url);
-
- TCMusicInfo* musicInfo = [TCMusicInfo new];
- musicInfo.duration = duration.floatValue;
- musicInfo.soneName = songName;
- musicInfo.singerName = authorName;
-
- if (mediaPicker.editing) {
- mediaPicker.editing = NO;
- dispatch_async(dispatch_get_main_queue(), ^{
- [self saveAssetURLToFile:musicInfo assetURL:url];
- });
-
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- }
- //点击取消时回调
- - (void)mediaPickerDidCancel:(MPMediaPickerController *)mediaPicker{
- [self dismissViewControllerAnimated:YES completion:nil];
- }
- // 将AssetURL(音乐)导出到app的文件夹并播放
- - (void)saveAssetURLToFile:(TCMusicInfo*)musicInfo assetURL:(NSURL*)assetURL {
-
- [_musixMixView addMusicInfo:musicInfo];
- }
- #pragma mark - VideoEffectViewDelegate
- - (void)onVideoEffectBeginClick:(TXEffectType)effectType {
- _effectType = effectType;
- switch ((TXEffectType)_effectType) {
- case TXEffectType_ROCK_LIGHT:
- [_videoCutView startColoration:UIColorFromRGB(0xEC5F9B) alpha:0.7];
- break;
- case TXEffectType_DARK_DRAEM:
- [_videoCutView startColoration:UIColorFromRGB(0xEC8435) alpha:0.7];
- break;
- case TXEffectType_SOUL_OUT:
- [_videoCutView startColoration:UIColorFromRGB(0x1FBCB6) alpha:0.7];
- break;
- case TXEffectType_SCREEN_SPLIT:
- [_videoCutView startColoration:UIColorFromRGB(0x449FF3) alpha:0.7];
- break;
- default:
- break;
- }
- [_ugcEdit startEffect:(TXEffectType)_effectType startTime:_playTime];
- if (!_isReverse) {
- [_ugcEdit startPlayFromTime:_videoCutView.videoRangeSlider.currentPos toTime:_videoCutView.videoRangeSlider.rightPos];
- }else{
- [_ugcEdit startPlayFromTime:_videoCutView.videoRangeSlider.leftPos toTime:_videoCutView.videoRangeSlider.currentPos];
- }
- [_videoPreview setPlayBtn:YES];
- }
- - (void)onVideoEffectEndClick:(TXEffectType)effectType {
- if (_effectType != -1) {
- [_videoPreview setPlayBtn:NO];
- [_videoCutView stopColoration];
- [_ugcEdit stopEffect:effectType endTime:_playTime];
- [_ugcEdit pausePlay];
- _effectType = -1;
- }
- }
- -(void)onEffectSelDelete{
- //删除特效
- [_videoCutView.videoRangeSlider removeLastColoration];
- [_ugcEdit deleteLastEffect];
-
- if (_videoCutView.videoRangeSlider.colorInfos.count<=0) {
- _effectSelectView.delEffectBtn.hidden = YES;
- }
- }
- #pragma mark TimeSelectViewDelegate
- - (void)onVideoTimeEffectsClear {
- _timeType = TimeType_Clear;
- _isReverse = NO;
- [_ugcEdit setReverse:_isReverse];
- [_ugcEdit setRepeatPlay:nil];
- [_ugcEdit setSpeedList:nil];
- [_ugcEdit startPlayFromTime:_videoCutView.videoRangeSlider.leftPos toTime:_videoCutView.videoRangeSlider.rightPos];
-
- [_videoPreview setPlayBtn:YES];
- [_videoCutView setCenterPanHidden:YES];
- }
- - (void)onVideoTimeEffectsBackPlay {
- _timeType = TimeType_Back;
- _isReverse = YES;
- [_ugcEdit setReverse:_isReverse];
- [_ugcEdit setRepeatPlay:nil];
- [_ugcEdit setSpeedList:nil];
- [_ugcEdit startPlayFromTime:_videoCutView.videoRangeSlider.leftPos toTime:_videoCutView.videoRangeSlider.rightPos];
- NSLog(@"left:%f\n right:%f",_videoCutView.videoRangeSlider.leftPos,_videoCutView.videoRangeSlider.rightPos);
- [_videoPreview setPlayBtn:YES];
- [_videoCutView setCenterPanHidden:YES];
- _videoCutView.videoRangeSlider.hidden = NO;
- }
- - (void)onVideoTimeEffectsRepeat {
- _timeType = TimeType_Repeat;
- _isReverse = NO;
- [_ugcEdit setReverse:_isReverse];
- [_ugcEdit setSpeedList:nil];
- TXRepeat *repeat = [[TXRepeat alloc] init];
- repeat.startTime = _leftTime + (_rightTime - _leftTime) / 5;
- repeat.endTime = repeat.startTime + 0.5;
- repeat.repeatTimes = 3;
- [_ugcEdit setRepeatPlay:@[repeat]];
- [_ugcEdit startPlayFromTime:_videoCutView.videoRangeSlider.leftPos toTime:_videoCutView.videoRangeSlider.rightPos];
-
- [_videoPreview setPlayBtn:YES];
- [_videoCutView setCenterPanHidden:NO];
- [_videoCutView setCenterPanFrame:repeat.startTime];
- }
- - (void)onVideoTimeEffectsSpeed {
- _timeType = TimeType_Speed;
- _isReverse = NO;
- [_ugcEdit setReverse:_isReverse];
- [_ugcEdit setRepeatPlay:nil];
- TXSpeed *speed =[[TXSpeed alloc] init];
- speed.startTime = _leftTime + (_rightTime - _leftTime) * 1.5 / 5;
- speed.endTime = _videoCutView.videoRangeSlider.rightPos;
- speed.speedLevel = SPEED_LEVEL_SLOW;
- [_ugcEdit setSpeedList:@[speed]];
- [_ugcEdit startPlayFromTime:_videoCutView.videoRangeSlider.leftPos toTime:_videoCutView.videoRangeSlider.rightPos];
-
- [_videoPreview setPlayBtn:YES];
- [_videoCutView setCenterPanHidden:NO];
- [_videoCutView setCenterPanFrame:speed.startTime];
- }
- //- (BOOL)prefersStatusBarHidden{
- // return NO;
- //}
- @end
- /*
- _startTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(15, _playProgressView.bottom + 10 * kScaleY, 50, 12)];
- _startTimeLabel.text = @"0:00";
- _startTimeLabel.textAlignment = NSTextAlignmentLeft;
- _startTimeLabel.font = [UIFont systemFontOfSize:12];
- _startTimeLabel.textColor = UIColor.lightTextColor;
- [self.view addSubview:_startTimeLabel];
-
- _endTimeLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.view.width - 15 - 50, _playProgressView.bottom + 10, 50, 12)];
- _endTimeLabel.text = @"0:00";
- _endTimeLabel.textAlignment = NSTextAlignmentRight;
- _endTimeLabel.font = [UIFont systemFontOfSize:12];
- _endTimeLabel.textColor = UIColor.lightTextColor;
- [self.view addSubview:_endTimeLabel];
- */
- /**
- - (void)saveAssetURLToFile:(TCMusicInfo*)musicInfo assetURL:(NSURL*)assetURL {
-
- [_musixMixView addMusicInfo:musicInfo];
-
- // AVURLAsset *songAsset = [AVURLAsset URLAssetWithURL:assetURL options:nil];
- //
- // AVAssetExportSession *exporter = [[AVAssetExportSession alloc] initWithAsset:songAsset presetName:AVAssetExportPresetAppleM4A];
- // NSLog (@"created exporter. supportedFileTypes: %@", exporter.supportedFileTypes);
- // exporter.outputFileType = @"com.apple.m4a-audio";
- //
- // [AVAssetExportSession exportPresetsCompatibleWithAsset:songAsset];
- // NSString *docDir = [[NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES) objectAtIndex:0] stringByAppendingPathComponent:@"LocalMusics/"];
- // NSString *exportFilePath = [docDir stringByAppendingPathComponent:[NSString stringWithFormat:@"%@_%@.m4a", musicInfo.soneName, musicInfo.singerName]];
- //
- // exporter.outputURL = [NSURL fileURLWithPath:exportFilePath];
- // musicInfo.filePath = exportFilePath;
- //
- // if ([[NSFileManager defaultManager] fileExistsAtPath:exportFilePath]) {
- // [_musixMixView addMusicInfo:musicInfo];
- // return;
- // }
- //
- // MBProgressHUD* hub = [MBProgressHUD showHUDAddedTo:self.view animated:YES];
- // hub.labelText = @"音频读取中...";
-
- // do the export
- //__weak typeof(self) weakSelf = self;
- // [exporter exportAsynchronouslyWithCompletionHandler:^{
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [MBProgressHUD hideHUDForView:self.view animated:YES];
- // });
- // int exportStatus = exporter.status;
- // switch (exportStatus) {
- // case AVAssetExportSessionStatusFailed: {
- // NSLog (@"AVAssetExportSessionStatusFailed: %@", exporter.error);
- // break;
- //
- // }
- // case AVAssetExportSessionStatusCompleted: {
- // NSLog(@"AVAssetExportSessionStatusCompleted: %@", exporter.outputURL);
- //
- // // 播放背景音乐
- // dispatch_async(dispatch_get_main_queue(), ^{
- // [_musixMixView addMusicInfo:musicInfo];
- // });
- // break;
- // }
- // case AVAssetExportSessionStatusUnknown: { NSLog (@"AVAssetExportSessionStatusUnknown"); break;}
- // case AVAssetExportSessionStatusExporting: { NSLog (@"AVAssetExportSessionStatusExporting"); break;}
- // case AVAssetExportSessionStatusCancelled: { NSLog (@"AVAssetExportSessionStatusCancelled"); break;}
- // case AVAssetExportSessionStatusWaiting: { NSLog (@"AVAssetExportSessionStatusWaiting"); break;}
- // default: { NSLog (@"didn't get export status"); break;}
- // }
- // }];
- }
-
- */
|