YOUPAIZYSendVideoVC.m 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238
  1. //
  2. // YOUPAIZYSendVideoVC.m
  3. // VQU
  4. //
  5. // Created by Elaine on 2020/11/6.
  6. // Copyright © 2020 leo. All rights reserved.
  7. //
  8. #import "YOUPAIZYSendVideoVC.h"
  9. #import "UIViewController+TFPresent.h"
  10. #import "LZAlertWindow.h"
  11. #import "YOUPAIZYSendVideoByLinkVC.h"
  12. #import "YOUPAIZYSendVideoByLocalVC.h"
  13. #import "YOUPAIVideoEditVC.h"//裁剪编辑页面
  14. #import "YOUPAISHMediaManager.h"//直接裁剪类
  15. @interface YOUPAIZYSendVideoVC ()
  16. @property (nonatomic,strong)UIButton *youpaiplocalBtn;
  17. @property (nonatomic,strong)UIButton *youpaiplinkBtn;
  18. @end
  19. @implementation YOUPAIZYSendVideoVC
  20. -(void)viewWillAppear:(BOOL)animated{
  21. [super viewWillAppear:YES];
  22. [self youpaifinitConfig];
  23. }
  24. - (void)youpaifinitConfig{ //系统配置信息
  25. WeakSelf;
  26. [LCHttpHelper requestWithURLString:AppConfig parameters:nil needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  27. NSDictionary* dict = (NSDictionary*)responseObject;
  28. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  29. if (code==0) {//成功
  30. NSInteger vt_watermark_open = [[[[dict objectForKey:@"data"]objectForKey:@"config"] objectForKey:@"vt_watermark_open"] integerValue];
  31. if (vt_watermark_open == 1) {
  32. weakSelf.youpaiplinkBtn.hidden = NO;
  33. weakSelf.youpaiplocalBtn.mj_x = CGRectGetMaxX(weakSelf.youpaiplinkBtn.frame) + 9.0f;
  34. weakSelf.youpaiplocalBtn.mj_w = (KScreenWidth - 28.0f - 9.0f) / 2.0;
  35. }else{
  36. weakSelf.youpaiplinkBtn.hidden = YES;
  37. weakSelf.youpaiplocalBtn.mj_x = 14.0f;
  38. weakSelf.youpaiplocalBtn.mj_w = KScreenWidth - 28.0f;
  39. }
  40. }
  41. } failure:^(NSError *error) {
  42. }];
  43. }
  44. - (void)viewDidLoad {
  45. [super viewDidLoad];
  46. self.title = @"发布视频";
  47. // self.view.backgroundColor = HexColorFromRGB(0xF6F6F6);
  48. [self youpaifrightClick];
  49. UIButton *rightBgV = [UIButton buttonWithType:UIButtonTypeCustom];
  50. rightBgV.frame = CGRectMake(0, 0, 44.0f, 44.0f);
  51. [rightBgV addTarget:self action:@selector(youpaifrightClick) forControlEvents:UIControlEventTouchUpInside];
  52. UIImageView *rightImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_D_senddynamic_right"]];
  53. rightImgV.frame = CGRectMake(44.0f - 16.0f, (44.0f - 16.0f) / 2.0f, 16.0f, 16.0f);
  54. [rightBgV addSubview:rightImgV];
  55. UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithCustomView:rightBgV];
  56. self.navigationItem.rightBarButtonItem = rightBarItem;//[UIBarButtonItem itemWithTarget:self action:@selector(youpaifrightClick) image:[UIImage imageNamed:@"ic_senddynamic_right"]];
  57. UIButton *button2 = [UIButton buttonWithType:UIButtonTypeCustom];
  58. button2.frame = CGRectMake(14.0f,25.0f + NavBarHeight,(KScreenWidth - 28.0f - 9.0f) / 2.0f,(KScreenWidth - 28.0f - 9.0f) / 2.0);
  59. [button2 setBackgroundColor:HexColorFromRGB(0x2A2935)];
  60. button2.layer.cornerRadius = 8.0f;
  61. button2.layer.masksToBounds = YES;
  62. [button2 setTitle:@"链接上传" forState:0];
  63. [button2 setTitleColor:[UIColor whiteColor] forState:0];
  64. button2.titleLabel.font = LCFont(15);
  65. [button2 setImage:[UIImage imageNamed:@"vqu_images_D_video_link"] forState:0];
  66. button2.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
  67. [button2 setTitleEdgeInsets:UIEdgeInsetsMake(button2.imageView.frame.size.height +10,-button2.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度,距离左边框减少imageView的宽度,距离下边框和右边框距离不变
  68. [button2 setImageEdgeInsets:UIEdgeInsetsMake(-30, 0.0,0.0, -button2.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度,其它不边
  69. button2.tag = 1;
  70. [button2 addTarget:self action:@selector(youpaifsendAction:) forControlEvents:UIControlEventTouchUpInside];
  71. [self.view addSubview:button2];
  72. self.youpaiplinkBtn = button2;
  73. UIButton *button1 = [UIButton buttonWithType:UIButtonTypeCustom];
  74. 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);
  75. [button1 setBackgroundColor:HexColorFromRGB(0x2A2935)];
  76. button1.layer.cornerRadius = 8;
  77. button1.layer.masksToBounds = YES;
  78. [button1 setTitle:@"本地上传" forState:0];
  79. [button1 setTitleColor:[UIColor whiteColor] forState:0];
  80. button1.titleLabel.font = LCFont(15);
  81. [button1 setImage:[UIImage imageNamed:@"vqu_images_D_video_local"] forState:0];
  82. button1.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;//使图片和文字水平居中显示
  83. [button1 setTitleEdgeInsets:UIEdgeInsetsMake(button1.imageView.frame.size.height +10,-button1.imageView.frame.size.width, 0.0,0.0)];//文字距离上边框的距离增加imageView的高度,距离左边框减少imageView的宽度,距离下边框和右边框距离不变
  84. [button1 setImageEdgeInsets:UIEdgeInsetsMake(-30, 0.0,0.0, -button1.titleLabel.bounds.size.width)];//图片距离右边框距离减少图片的宽度,其它不边
  85. button1.tag = 2;
  86. [button1 addTarget:self action:@selector(youpaifsendAction:) forControlEvents:UIControlEventTouchUpInside];
  87. [self.view addSubview:button1];
  88. self.youpaiplocalBtn = button1;
  89. // UILabel*label1 = [[UILabel alloc]initWithFrame:CGRectMake(33,KScreenHeight-190-21,100,21)];
  90. // label1.textColor = HexColorFromRGB(0x666666);
  91. // label1.font = LCFont(15);
  92. // label1.text = @"发布须知:";
  93. // [self.view addSubview:label1];
  94. //
  95. //
  96. //
  97. // UILabel* label2 = [[UILabel alloc]initWithFrame:CGRectMake(33,KScreenHeight-180,KScreenWidth-33-33,80)];
  98. // label2.textColor = HexColorFromRGB(0x999999);
  99. // label2.font = LCFont(13);
  100. // label2.numberOfLines = 0;
  101. // label2.text = @"1、视频不可以有抖音或快手等平台水印;\n2、禁止发布色情,性暗示等低俗内容;\n3、禁止发布国家政治,暴恐暴乱等内容;\n4、不可使用他人的视频发布。";
  102. // [self.view addSubview:label2];
  103. // [label2 setValue:@(20) forKey:@"lineSpacing"];
  104. }
  105. //提示
  106. -(void)youpaifrightClick
  107. {
  108. LZAlertAction *action = [LZAlertAction actionWithTitle:@"我知道了" handler:^(LZAlertAction *action) {
  109. }];
  110. action.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 128.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]];
  111. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"发布须知" content:@"1、禁止发布色情,性暗示等低俗内容;\n\n2、禁止发布国家政治,暴恐暴乱等内容;\n\n3、不可涉及第三方平台信息;\n\n4、不可使用他人的图片或视频发布。" action:@[action]];
  112. alert.contentFont = LCFont16;
  113. alert.contentHorizontalSpace = 32.0f;
  114. [self TFPresentVC:alert completion:^{}];
  115. }
  116. -(void)youpaifsendAction:(UIButton *)sender
  117. {
  118. if (sender.tag == 1) {// 链接上传
  119. YOUPAIZYSendVideoByLinkVC *vc = [[YOUPAIZYSendVideoByLinkVC alloc] init];
  120. [self pushEffectPresentToVC:vc];
  121. }else{// 本地上传
  122. [self youpaifopenAlbum];
  123. }
  124. }
  125. - (void)youpaifopenAlbum{
  126. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 columnNumber:4 delegate:nil];
  127. [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVc];
  128. imagePickerVc.allowTakePicture = YES; // 在内部显示拍照按钮
  129. imagePickerVc.allowPickingVideo = YES;//是否允许选择视频
  130. imagePickerVc.allowPickingImage = NO;//是否允许选择照片
  131. imagePickerVc.allowPickingOriginalPhoto = NO;//是否选择原图
  132. imagePickerVc.showSelectedIndex = YES; //显示图片序号
  133. // 4. 照片排列按修改时间升序
  134. imagePickerVc.sortAscendingByModificationDate = YES;//按时间倒序排列图片
  135. // 你可以通过block或者代理,来得到用户选择的照片.
  136. [imagePickerVc setDidFinishPickingVideoHandle:^(UIImage *coverImage, PHAsset *asset) {
  137. PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
  138. options.version = PHVideoRequestOptionsVersionOriginal;
  139. options.deliveryMode = PHImageRequestOptionsDeliveryModeOpportunistic;
  140. options.networkAccessAllowed = YES;
  141. [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:nil resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
  142. AVURLAsset *urlAsser = ( AVURLAsset *)asset;
  143. NSString *videoPath =[urlAsser.URL absoluteString];
  144. NSLog(@"%@",videoPath);
  145. NSLog(@"%@",info);
  146. CMTime time = [asset duration];
  147. int seconds = ceil(time.value/time.timescale);
  148. NSLog(@"视频时长seconds = %d",seconds);
  149. dispatch_sync(dispatch_get_main_queue(), ^{
  150. if (seconds > 60) {
  151. //视频时长大于60s将自动裁剪前60秒进行上传
  152. [self youpaifisCutVideo:videoPath andImage:coverImage];//是否裁剪视频进行上传
  153. }else{
  154. //裁剪
  155. // YOUPAIVideoEditVC *videoEditVC = [[YOUPAIVideoEditVC alloc] init];
  156. // videoEditVC.videoUrl = [NSURL URLWithString:videoPath];
  157. // [self.navigationController pushViewController:videoEditVC animated:YES];
  158. YOUPAIZYSendVideoByLocalVC *vc = [[YOUPAIZYSendVideoByLocalVC alloc] init];
  159. vc.youpaipcoverImage = coverImage;
  160. vc.youpaipvideoFileName = videoPath;
  161. [self pushEffectPresentToVC:vc];
  162. }
  163. });
  164. }];
  165. }];
  166. [self presentViewController:imagePickerVc animated:YES completion:nil];
  167. }
  168. -(void)youpaifisCutVideo:(NSString *)videoPath andImage:(UIImage *)coverImage
  169. {
  170. NSLog(@"%@",videoPath);
  171. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"视频时长大于60秒将自动裁剪前60秒进行上传" preferredStyle:UIAlertControllerStyleAlert];
  172. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  173. }];
  174. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  175. [ZCHUDHelper showWithStatus:@"正在裁剪..."];
  176. NSURL *url = [NSURL URLWithString:videoPath];
  177. NSLog(@"url == %@",url);
  178. [YOUPAISHMediaManager youpaifcropWithVideoUrlStr:url start:1.0 end:60.0 completion:^(NSURL *outputURL, Float64 videoDuration, BOOL isSuccess) {
  179. if (isSuccess) {
  180. NSLog(@"-转码完成------\n路径:%@",outputURL);
  181. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  182. dispatch_async(dispatch_get_main_queue(), ^{
  183. [ZCHUDHelper showTitle:@"裁剪完成"];
  184. YOUPAIZYSendVideoByLocalVC *vc = [[YOUPAIZYSendVideoByLocalVC alloc] init];
  185. vc.youpaipcoverImage = coverImage;
  186. vc.youpaipvideoFileName = [outputURL absoluteString];
  187. [self pushEffectPresentToVC:vc];
  188. });
  189. });
  190. }else{
  191. [ZCHUDHelper showTitle:@"裁剪失败"];
  192. }
  193. }];
  194. }];
  195. [alertController addAction:cancelAction];
  196. [alertController addAction:okAction];
  197. [self presentViewController:alertController animated:YES completion:nil];
  198. }
  199. @end