123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238 |
- //
- // YOUPAIZYSendVideoVC.m
- // VQU
- //
- // Created by Elaine on 2020/11/6.
- // Copyright © 2020 leo. All rights reserved.
- //
- #import "YOUPAIZYSendVideoVC.h"
- #import "UIViewController+TFPresent.h"
- #import "LZAlertWindow.h"
- #import "YOUPAIZYSendVideoByLinkVC.h"
- #import "YOUPAIZYSendVideoByLocalVC.h"
- #import "YOUPAIVideoEditVC.h"//裁剪编辑页面
- #import "YOUPAISHMediaManager.h"//直接裁剪类
- @interface YOUPAIZYSendVideoVC ()
- @property (nonatomic,strong)UIButton *youpaiplocalBtn;
- @property (nonatomic,strong)UIButton *youpaiplinkBtn;
- @end
- @implementation YOUPAIZYSendVideoVC
- -(void)viewWillAppear:(BOOL)animated{
- [super viewWillAppear:YES];
- [self youpaifinitConfig];
- }
- - (void)youpaifinitConfig{ //系统配置信息
- WeakSelf;
- [LCHttpHelper requestWithURLString:AppConfig parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- NSInteger vt_watermark_open = [[[[dict objectForKey:@"data"]objectForKey:@"config"] objectForKey:@"vt_watermark_open"] integerValue];
- if (vt_watermark_open == 1) {
- weakSelf.youpaiplinkBtn.hidden = NO;
- weakSelf.youpaiplocalBtn.mj_x = CGRectGetMaxX(weakSelf.youpaiplinkBtn.frame) + 9.0f;
- weakSelf.youpaiplocalBtn.mj_w = (KScreenWidth - 28.0f - 9.0f) / 2.0;
- }else{
- weakSelf.youpaiplinkBtn.hidden = YES;
- weakSelf.youpaiplocalBtn.mj_x = 14.0f;
- weakSelf.youpaiplocalBtn.mj_w = KScreenWidth - 28.0f;
- }
-
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.title = @"发布视频";
- // self.view.backgroundColor = HexColorFromRGB(0xF6F6F6);
-
- [self youpaifrightClick];
-
- UIButton *rightBgV = [UIButton buttonWithType:UIButtonTypeCustom];
- rightBgV.frame = CGRectMake(0, 0, 44.0f, 44.0f);
- [rightBgV addTarget:self action:@selector(youpaifrightClick) forControlEvents:UIControlEventTouchUpInside];
- UIImageView *rightImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_D_senddynamic_right"]];
- rightImgV.frame = CGRectMake(44.0f - 16.0f, (44.0f - 16.0f) / 2.0f, 16.0f, 16.0f);
- [rightBgV addSubview:rightImgV];
- UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithCustomView:rightBgV];
- self.navigationItem.rightBarButtonItem = rightBarItem;//[UIBarButtonItem itemWithTarget:self action:@selector(youpaifrightClick) image:[UIImage imageNamed:@"ic_senddynamic_right"]];
- UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
- button2.frame = CGRectMake(14.0f,25.0f + NavBarHeight,(KScreenWidth - 28.0f - 9.0f) / 2.0f,(KScreenWidth - 28.0f - 9.0f) / 2.0);
- [button2 setBackgroundColor:HexColorFromRGB(0x2A2935)];
- button2.layer.cornerRadius = 8.0f;
- button2.layer.masksToBounds = YES;
- [button2 setTitle:@"链接上传" forState:0];
- [button2 setTitleColor:[UIColor whiteColor] forState:0];
- button2.titleLabel.font = LCFont(15);
- [button2 setImage:[UIImage imageNamed:@"vqu_images_D_video_link"] forState:0];
- button2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
- [button2 setTitleEdgeInsets:UIEdgeInsetsMake(button2.imageView.frame.size.height +10,-button2.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度,距离左边框减少imageView的宽度,距离下边框和右边框距离不变
- [button2 setImageEdgeInsets:UIEdgeInsetsMake(-30, 0.0,0.0, -button2.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度,其它不边
- button2.tag = 1;
- [button2 addTarget:self action:@selector(youpaifsendAction:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:button2];
- self.youpaiplinkBtn = button2;
-
- UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
- button1.frame = CGRectMake(CGRectGetMaxX(button2.frame) + 9.0f,25.0f + NavBarHeight,(KScreenWidth - 28.0f - 9.0f) / 2.0f,(KScreenWidth - 28.0f - 9.0f) / 2.0);
- [button1 setBackgroundColor:HexColorFromRGB(0x2A2935)];
- button1.layer.cornerRadius = 8;
- button1.layer.masksToBounds = YES;
- [button1 setTitle:@"本地上传" forState:0];
- [button1 setTitleColor:[UIColor whiteColor] forState:0];
- button1.titleLabel.font = LCFont(15);
- [button1 setImage:[UIImage imageNamed:@"vqu_images_D_video_local"] forState:0];
- button1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
- [button1 setTitleEdgeInsets:UIEdgeInsetsMake(button1.imageView.frame.size.height +10,-button1.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度,距离左边框减少imageView的宽度,距离下边框和右边框距离不变
- [button1 setImageEdgeInsets:UIEdgeInsetsMake(-30, 0.0,0.0, -button1.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度,其它不边
- button1.tag = 2;
- [button1 addTarget:self action:@selector(youpaifsendAction:) forControlEvents:UIControlEventTouchUpInside];
- [self.view addSubview:button1];
- self.youpaiplocalBtn = button1;
-
-
-
- // UILabel*label1 = [[UILabel alloc]initWithFrame:CGRectMake(33,KScreenHeight-190-21,100,21)];
- // label1.textColor = HexColorFromRGB(0x666666);
- // label1.font = LCFont(15);
- // label1.text = @"发布须知:";
- // [self.view addSubview:label1];
- //
- //
- //
- // UILabel* label2 = [[UILabel alloc]initWithFrame:CGRectMake(33,KScreenHeight-180,KScreenWidth-33-33,80)];
- // label2.textColor = HexColorFromRGB(0x999999);
- // label2.font = LCFont(13);
- // label2.numberOfLines = 0;
- // label2.text = @"1、视频不可以有抖音或快手等平台水印;\n2、禁止发布色情,性暗示等低俗内容;\n3、禁止发布国家政治,暴恐暴乱等内容;\n4、不可使用他人的视频发布。";
- // [self.view addSubview:label2];
- // [label2 setValue:@(20) forKey:@"lineSpacing"];
-
- }
- //提示
- -(void)youpaifrightClick
- {
- LZAlertAction *action = [LZAlertAction actionWithTitle:@"我知道了" handler:^(LZAlertAction *action) {
-
- }];
- action.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 128.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]];
- LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"发布须知" content:@"1、禁止发布色情,性暗示等低俗内容;\n\n2、禁止发布国家政治,暴恐暴乱等内容;\n\n3、不可涉及第三方平台信息;\n\n4、不可使用他人的图片或视频发布。" action:@[action]];
- alert.contentFont = LCFont16;
- alert.contentHorizontalSpace = 32.0f;
- [self TFPresentVC:alert completion:^{}];
- }
- -(void)youpaifsendAction:(UIButton *)sender
- {
- if (sender.tag == 1) {// 链接上传
- YOUPAIZYSendVideoByLinkVC *vc = [[YOUPAIZYSendVideoByLinkVC alloc] init];
- [self pushEffectPresentToVC:vc];
- }else{// 本地上传
- [self youpaifopenAlbum];
-
-
- }
- }
- - (void)youpaifopenAlbum{
-
- TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 columnNumber:4 delegate:nil];
- [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVc];
- imagePickerVc.allowTakePicture = YES; // 在内部显示拍照按钮
- imagePickerVc.allowPickingVideo = YES;//是否允许选择视频
- imagePickerVc.allowPickingImage = NO;//是否允许选择照片
- imagePickerVc.allowPickingOriginalPhoto = NO;//是否选择原图
- imagePickerVc.showSelectedIndex = YES; //显示图片序号
- // 4. 照片排列按修改时间升序
- imagePickerVc.sortAscendingByModificationDate = YES;//按时间倒序排列图片
- // 你可以通过block或者代理,来得到用户选择的照片.
- [imagePickerVc setDidFinishPickingVideoHandle:^(UIImage *coverImage, PHAsset *asset) {
-
- PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
- options.version = PHVideoRequestOptionsVersionOriginal;
- options.deliveryMode = PHImageRequestOptionsDeliveryModeOpportunistic;
- options.networkAccessAllowed = YES;
-
- [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:nil resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
- AVURLAsset *urlAsser = ( AVURLAsset *)asset;
- NSString *videoPath =[urlAsser.URL absoluteString];
-
- NSLog(@"%@",videoPath);
- NSLog(@"%@",info);
-
-
-
-
- CMTime time = [asset duration];
- int seconds = ceil(time.value/time.timescale);
- NSLog(@"视频时长seconds = %d",seconds);
-
- dispatch_sync(dispatch_get_main_queue(), ^{
- if (seconds > 60) {
- //视频时长大于60s将自动裁剪前60秒进行上传
- [self youpaifisCutVideo:videoPath andImage:coverImage];//是否裁剪视频进行上传
- }else{
- //裁剪
- // YOUPAIVideoEditVC *videoEditVC = [[YOUPAIVideoEditVC alloc] init];
- // videoEditVC.videoUrl = [NSURL URLWithString:videoPath];
- // [self.navigationController pushViewController:videoEditVC animated:YES];
- YOUPAIZYSendVideoByLocalVC *vc = [[YOUPAIZYSendVideoByLocalVC alloc] init];
- vc.youpaipcoverImage = coverImage;
- vc.youpaipvideoFileName = videoPath;
- [self pushEffectPresentToVC:vc];
- }
- });
- }];
-
-
- }];
- [self presentViewController:imagePickerVc animated:YES completion:nil];
- }
- -(void)youpaifisCutVideo:(NSString *)videoPath andImage:(UIImage *)coverImage
- {
-
- NSLog(@"%@",videoPath);
-
- UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"视频时长大于60秒将自动裁剪前60秒进行上传" preferredStyle:UIAlertControllerStyleAlert];
- UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
- }];
- UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
- [ZCHUDHelper showWithStatus:@"正在裁剪..."];
-
- NSURL *url = [NSURL URLWithString:videoPath];
- NSLog(@"url == %@",url);
-
- [YOUPAISHMediaManager youpaifcropWithVideoUrlStr:url start:1.0 end:60.0 completion:^(NSURL *outputURL, Float64 videoDuration, BOOL isSuccess) {
- if (isSuccess) {
- NSLog(@"-转码完成------\n路径:%@",outputURL);
- dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
- dispatch_async(dispatch_get_main_queue(), ^{
- [ZCHUDHelper showTitle:@"裁剪完成"];
- YOUPAIZYSendVideoByLocalVC *vc = [[YOUPAIZYSendVideoByLocalVC alloc] init];
- vc.youpaipcoverImage = coverImage;
- vc.youpaipvideoFileName = [outputURL absoluteString];
- [self pushEffectPresentToVC:vc];
- });
- });
- }else{
- [ZCHUDHelper showTitle:@"裁剪失败"];
- }
- }];
- }];
- [alertController addAction:cancelAction];
- [alertController addAction:okAction];
- [self presentViewController:alertController animated:YES completion:nil];
- }
- @end
|