YOUPAIZYSendVideoByLocalVC.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. //
  2. // YOUPAIZYSendVideoByLocalVC.m
  3. // VQU
  4. //
  5. // Created by Elaine on 2020/11/9.
  6. // Copyright © 2020 leo. All rights reserved.
  7. //
  8. #import "YOUPAIZYSendVideoByLocalVC.h"
  9. #import "UIViewController+TFPresent.h"
  10. #import "YOUPAILPChatTipView.h"
  11. #import "LZAlertWindow.h"
  12. #import <AVKit/AVKit.h>
  13. #import <VODUpload/VODUploadClient.h>
  14. #import <AliyunOSSiOS/OSSService.h>
  15. #import "YOUPAISHMediaManager.h"//直接裁剪类
  16. #import "YOUPAILZTextView.h"
  17. @interface YOUPAIZYSendVideoByLocalVC ()
  18. {
  19. VODUploadClient *youpaipuploader;
  20. }
  21. @property (nonatomic,strong)YOUPAILZTextView* youpaipliveView;
  22. @property(nonatomic,strong)UIImageView *youpaipvideoImgView;//
  23. @property(nonatomic,strong)UIButton *youpaipsendVideoBtn;//发布视频
  24. @property(nonatomic,strong)UIButton *youpaipdeleBtn;//删除按钮
  25. @property(nonatomic,strong)UIButton *youpaipplayVideoBtn;//播放按钮
  26. @property(nonatomic,strong)UIButton *youpaipaddVideoBtn;//播放按钮
  27. @end
  28. @implementation YOUPAIZYSendVideoByLocalVC
  29. -(void)viewWillAppear:(BOOL)animated
  30. {
  31. [super viewWillAppear:animated];
  32. // [self youpaifaddTip];
  33. }
  34. - (void)youpaifaddTip{
  35. NSString *tip = @"请勿涉及色情,广告等违规内容,违者将永久封号";
  36. YOUPAILPChatTipView* chatTip = [[YOUPAILPChatTipView alloc]initWithFrame:CGRectMake(0,NavBarHeight-40, KScreenWidth, 40)];
  37. chatTip.tipLabel.text = tip;
  38. [self.view addSubview:chatTip];
  39. [UIView animateWithDuration:1 animations:^{
  40. chatTip.frame = CGRectMake(0,NavBarHeight, KScreenWidth, 40);
  41. }completion:^(BOOL finished) {
  42. if (finished) {
  43. dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
  44. [UIView animateWithDuration:1 animations:^{
  45. chatTip.frame = CGRectMake(0,NavBarHeight-40, KScreenWidth, 40);
  46. }completion:^(BOOL finished) {
  47. if (finished) {
  48. [chatTip removeFromSuperview];
  49. }
  50. }];
  51. });
  52. }
  53. }];
  54. }
  55. - (void)viewDidLoad {
  56. [super viewDidLoad];
  57. // [self youpaifopenAlbum];
  58. if (self.youpaipisDynamicVC) {
  59. self.title = @"视频上传";
  60. }else{
  61. self.title = @"本地上传";
  62. }
  63. self.view.backgroundColor = [UIColor whiteColor];
  64. // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(youpaifhideTheKeyboard)];
  65. // [self.view addGestureRecognizer:tap];
  66. self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifcancelClick) image:[UIImage imageNamed:@"vqu_images_navigation_back_black"]];
  67. UIButton *rightBgV = [UIButton buttonWithType:UIButtonTypeCustom];
  68. rightBgV.frame = CGRectMake(0, 0, 44.0f, 44.0f);
  69. [rightBgV addTarget:self action:@selector(youpaifrightClick) forControlEvents:UIControlEventTouchUpInside];
  70. UIImageView *rightImgV = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"vqu_images_D_senddynamic_right"]];
  71. rightImgV.frame = CGRectMake(44.0f - 16.0f, (44.0f - 16.0f) / 2.0f, 16.0f, 16.0f);
  72. [rightBgV addSubview:rightImgV];
  73. UIBarButtonItem *rightBarItem = [[UIBarButtonItem alloc] initWithCustomView:rightBgV];
  74. self.navigationItem.rightBarButtonItem = rightBarItem;//[UIBarButtonItem itemWithTarget:self action:@selector(youpaifrightClick) image:[UIImage imageNamed:@"ic_senddynamic_right"]];
  75. YOUPAILZTextView *textView = [[YOUPAILZTextView alloc] initWithMaxCount:100];
  76. textView.frame = CGRectMake(14.0f, 25.0f+NavBarHeight, KScreenWidth-28, 148.0f);
  77. textView.youpaiptextViewPadding = UIEdgeInsetsMake(14.0f, 14.0f, 10.0f, 14.0f);
  78. textView.youpaiptextLengthDefaultColor = LZD3D1D7Color;
  79. textView.youpaiptextLengthHigtColor = LZ7C69FEColor;
  80. textView.youpaiptextLengthFont = LCFont(14.0f);
  81. textView.youpaiptextLengthRight = 14.0f;
  82. textView.youpaiptextLengthBottom = 14.0f;
  83. textView.youpaiptextView.placeholderFont = LCFont(14.0f);
  84. textView.youpaiptextView.placeholderTextColor = LZD3D1D7Color;
  85. textView.youpaiptextView.placeholderText = @"这一刻你想说点什么…";
  86. textView.youpaiptextView.font = LCFont(14.0f);
  87. textView.layer.cornerRadius = 5.0f;
  88. textView.clipsToBounds = YES;
  89. textView.tintColor = LZ7C69FEColor;
  90. [self.view addSubview:textView];
  91. textView.youpaiptextView.textColor = LZ273145Color;
  92. self.youpaipliveView = textView;
  93. textView.backgroundColor = LZF7F8FAColor;
  94. UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(14.0f,CGRectGetMaxY(textView.frame)+14.0f,150,267)];
  95. imgView.userInteractionEnabled = YES;
  96. imgView.contentMode = UIViewContentModeScaleAspectFill;
  97. imgView.layer.cornerRadius = 5.0;
  98. imgView.clipsToBounds=YES;
  99. self.youpaipvideoImgView = imgView;
  100. self.youpaipvideoImgView.image = self.youpaipcoverImage;
  101. [self.view addSubview:imgView];
  102. //添加按钮
  103. UIButton *addVideoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  104. addVideoBtn.frame = CGRectMake(14.0f,CGRectGetMaxY(textView.frame)+14.0f,173,230);
  105. [addVideoBtn setImage:[UIImage imageNamed:@"vqu_images_D_dynamic_New_add"] forState:0];
  106. [addVideoBtn addTarget:self action:@selector(youpaifAddNewVideoClick) forControlEvents:UIControlEventTouchUpInside];
  107. [self.view addSubview:addVideoBtn];
  108. self.youpaipaddVideoBtn = addVideoBtn;
  109. addVideoBtn.hidden = YES;
  110. UIButton *playVideoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  111. playVideoBtn.frame = CGRectMake(50,105,50,50);
  112. [playVideoBtn setImage:[UIImage imageNamed:@"vqu_images_D_video_play"] forState:0];
  113. [playVideoBtn addTarget:self action:@selector(youpaifplayVideoAction) forControlEvents:UIControlEventTouchUpInside];
  114. [imgView addSubview:playVideoBtn];
  115. self.youpaipplayVideoBtn = playVideoBtn;
  116. //删除按钮
  117. UIButton *deleBtn = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imgView.frame)-38, 8, 20, 20)];
  118. [deleBtn setImage:[UIImage imageNamed:@"vqu_images_D_dynamic_dele"] forState:UIControlStateNormal];
  119. self.youpaipdeleBtn = deleBtn;
  120. [deleBtn addTarget:self action:@selector(youpaifdeleVideoAction) forControlEvents:UIControlEventTouchUpInside];
  121. [imgView addSubview:deleBtn];
  122. self.youpaipsendVideoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  123. self.youpaipsendVideoBtn.frame = CGRectMake(40.0f,KScreenHeight-77-SafeHeight,KScreenWidth - 80.0f,48);
  124. [self.youpaipsendVideoBtn setTitle:@"发布视频" forState:0];
  125. [self.youpaipsendVideoBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:0];
  126. self.youpaipsendVideoBtn.titleLabel.font = LCFont(16);
  127. self.youpaipsendVideoBtn.layer.cornerRadius = 24;
  128. self.youpaipsendVideoBtn.layer.masksToBounds = YES;
  129. [self.youpaipsendVideoBtn addTarget:self action:@selector(youpaifsendClick) forControlEvents:UIControlEventTouchUpInside];
  130. [self.youpaipsendVideoBtn setBackgroundImage:[LCTools ColorImage:self.youpaipsendVideoBtn.frame.size FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)];
  131. [self.view addSubview:self.youpaipsendVideoBtn];
  132. youpaipuploader = [VODUploadClient new];
  133. }
  134. //删除
  135. -(void)youpaifdeleVideoAction{
  136. self.youpaipdeleBtn.hidden = YES;
  137. self.youpaipplayVideoBtn.hidden = YES;
  138. self.youpaipvideoFileName = nil;
  139. [UIView animateWithDuration:0.1 animations:^{
  140. self.youpaipvideoImgView.hidden = YES;
  141. self.youpaipaddVideoBtn.hidden = NO;
  142. }];
  143. }
  144. -(void)youpaifAddNewVideoClick{
  145. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 columnNumber:4 delegate:nil];
  146. [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVc];
  147. imagePickerVc.allowTakePicture = YES; // 在内部显示拍照按钮
  148. imagePickerVc.allowPickingVideo = YES;//是否允许选择视频
  149. imagePickerVc.allowPickingImage = NO;//是否允许选择照片
  150. imagePickerVc.allowPickingOriginalPhoto = NO;//是否选择原图
  151. imagePickerVc.showSelectedIndex = YES; //显示图片序号
  152. // 4. 照片排列按修改时间升序
  153. imagePickerVc.sortAscendingByModificationDate = YES;//按时间倒序排列图片
  154. // 你可以通过block或者代理,来得到用户选择的照片.
  155. @weakify(self);
  156. [imagePickerVc setDidFinishPickingVideoHandle:^(UIImage *coverImage, PHAsset *asset) {
  157. @strongify(self);
  158. PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
  159. options.version = PHVideoRequestOptionsVersionOriginal;
  160. options.deliveryMode = PHImageRequestOptionsDeliveryModeOpportunistic;
  161. options.networkAccessAllowed = YES;
  162. [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:nil resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
  163. AVURLAsset *urlAsser = ( AVURLAsset *)asset;
  164. NSString *videoPath =[urlAsser.URL absoluteString];
  165. if (asset == nil) {
  166. [ZCHUDHelper showTitle:@"无效视频"];
  167. return;
  168. }
  169. NSLog(@"%@",videoPath);
  170. NSLog(@"%@",info);
  171. CMTime time = [asset duration];
  172. int seconds = ceil(time.value/time.timescale);
  173. NSLog(@"视频时长seconds = %d",seconds);
  174. dispatch_sync(dispatch_get_main_queue(), ^{
  175. if (seconds > 60) {
  176. //视频时长大于60s将自动裁剪前60秒进行上传
  177. [self youpaifisCutVideo:videoPath andImage:coverImage];//是否裁剪视频进行上传
  178. }else{
  179. //裁剪
  180. // YOUPAIVideoEditVC *videoEditVC = [[YOUPAIVideoEditVC alloc] init];
  181. // videoEditVC.videoUrl = [NSURL URLWithString:videoPath];
  182. // [self.navigationController pushViewController:videoEditVC animated:YES];
  183. self.youpaipvideoImgView.image = coverImage;
  184. self.youpaipvideoFileName = videoPath;
  185. self.youpaipdeleBtn.hidden = NO;
  186. self.youpaipplayVideoBtn.hidden = NO;
  187. [UIView animateWithDuration:0.1 animations:^{
  188. self.youpaipaddVideoBtn.hidden = YES;
  189. self.youpaipvideoImgView.hidden = NO;
  190. }];
  191. }
  192. });
  193. }];
  194. }];
  195. [self presentViewController:imagePickerVc animated:YES completion:nil];
  196. }
  197. -(void)youpaifisCutVideo:(NSString *)videoPath andImage:(UIImage *)coverImage
  198. {
  199. NSLog(@"%@",videoPath);
  200. UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"视频时长大于60秒将自动裁剪前60秒进行上传" preferredStyle:UIAlertControllerStyleAlert];
  201. UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  202. }];
  203. UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"确定上传" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  204. [ZCHUDHelper showWithStatus:@"正在裁剪..."];
  205. NSURL *url = [NSURL URLWithString:videoPath];
  206. NSLog(@"url == %@",url);
  207. [YOUPAISHMediaManager youpaifcropWithVideoUrlStr:url start:1.0 end:60.0 completion:^(NSURL *outputURL, Float64 videoDuration, BOOL isSuccess) {
  208. if (isSuccess) {
  209. NSLog(@"-转码完成------\n路径:%@",outputURL);
  210. dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
  211. dispatch_async(dispatch_get_main_queue(), ^{
  212. [ZCHUDHelper showTitle:@"裁剪完成"];
  213. self.youpaipvideoImgView.image = coverImage;
  214. self.youpaipvideoFileName = videoPath;
  215. self.youpaipdeleBtn.hidden = NO;
  216. self.youpaipplayVideoBtn.hidden = NO;
  217. [UIView animateWithDuration:0.1 animations:^{
  218. self.youpaipaddVideoBtn.hidden = YES;
  219. self.youpaipvideoImgView.hidden = NO;
  220. }];
  221. });
  222. });
  223. }else{
  224. [ZCHUDHelper showTitle:@"裁剪失败"];
  225. }
  226. }];
  227. }];
  228. [alertController addAction:cancelAction];
  229. [alertController addAction:okAction];
  230. [self presentViewController:alertController animated:YES completion:nil];
  231. }
  232. - (void)youpaifcancelClick{
  233. [self popEffectDismiss];
  234. // self.sendModel.tit = self.liveView.textView.text;
  235. // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"要保存草稿吗?" preferredStyle:UIAlertControllerStyleAlert];
  236. // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"放弃" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  237. // // [LCSaveModel saveSendDynamicModel:nil];
  238. // [self popEffectDismiss];
  239. // }];
  240. // UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"保存" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){
  241. // // [LCSaveModel saveSendDynamicModel:self.sendModel];
  242. // [self popEffectDismiss];
  243. // }];
  244. // [alertController addAction:cancelAction];
  245. // [alertController addAction:okAction];
  246. // [self presentViewController:alertController animated:YES completion:nil];
  247. }
  248. //提示
  249. -(void)youpaifrightClick
  250. {
  251. LZAlertAction *action = [LZAlertAction actionWithTitle:@"我知道了" handler:^(LZAlertAction *action) {
  252. }];
  253. action.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake(KScreenWidth - 128.0f, 48.0f) FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:GradientLeftToRight]];
  254. LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"发布须知" content:@"1、禁止发布色情,性暗示等低俗内容;\n\n2、禁止发布国家政治,暴恐暴乱等内容;\n\n3、不可涉及第三方平台信息;\n\n4、不可使用他人的图片或视频发布。" action:@[action]];
  255. alert.contentFont = LCFont16;
  256. alert.contentHorizontalSpace = 32.0f;
  257. [self TFPresentVC:alert completion:^{}];
  258. }
  259. - (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
  260. [self youpaifhideTheKeyboard];
  261. }
  262. //发布视频
  263. -(void)youpaifsendClick
  264. {
  265. if (self.youpaipliveView.youpaiptextView.text.length == 0) {
  266. [ZCHUDHelper showTitle:@"文字不能为空"];
  267. return;
  268. }
  269. if (self.youpaipvideoFileName == nil) {
  270. [ZCHUDHelper showTitle:@"请选择视频"];
  271. return;
  272. }
  273. __weak VODUploadClient *weakClient = youpaipuploader;
  274. __weak YOUPAIZYSendVideoByLocalVC *weakSelf = self;
  275. if (self.youpaipisDynamicVC) {
  276. [LCHttpHelper requestWithURLString:DynamicPub parameters:@{@"videoFileName":self.youpaipvideoFileName,@"content":self.youpaipliveView.youpaiptextView.text,@"type":@"1"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  277. NSDictionary* dict = (NSDictionary*)responseObject;
  278. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  279. if (code==0) {//成功
  280. NSString* dynamicId = [[dict objectForKey:@"data"]objectForKey:@"dynamic_id"];
  281. [ZCHUDHelper show];
  282. [LCCommonHttp uploadWithVideoPath:self.youpaipvideoFileName Type:@"dynamic" successBlock:^(NSString *ossFilePath) {
  283. [LCHttpHelper requestWithURLString:DynamicUpdateImage parameters:@{@"images":ossFilePath, @"dynamic_id":dynamicId, @"type":@"1"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  284. NSDictionary* dict = (NSDictionary*)responseObject;
  285. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  286. if (code==0) {
  287. [LCSaveModel saveSendDynamicModel:nil];
  288. }
  289. [ZCHUDHelper dismiss];
  290. [self popEffectDismiss];
  291. } failure:^(NSError *error) {
  292. [ZCHUDHelper dismiss];
  293. [ZCHUDHelper showTitle:@"发布失败"];
  294. [self popEffectDismiss];
  295. }];
  296. }];
  297. }
  298. } failure:^(NSError *error) {
  299. }];
  300. }
  301. else{
  302. [LCHttpHelper requestWithURLString:TrendsSave parameters:@{@"videoFileName":self.youpaipvideoFileName,@"content":self.youpaipliveView.youpaiptextView.text} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  303. NSDictionary* dict = (NSDictionary*)responseObject;
  304. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  305. if (code==0) {//成功
  306. NSString *UploadAddress = [[dict objectForKey:@"data"] objectForKey:@"UploadAddress"];
  307. NSString *UploadAuth = [[dict objectForKey:@"data"] objectForKey:@"UploadAuth"];
  308. // NSString *VideoId = [[dict objectForKey:@"data"] objectForKey:@"VideoId"];
  309. // NSString *RequestId = [[dict objectForKey:@"data"] objectForKey:@"RequestId"];
  310. // callback functions and listener
  311. OnUploadFinishedListener testFinishCallbackFunc = ^(UploadFileInfo* fileInfo, VodUploadResult* result){
  312. NSLog(@"wz on upload finished videoid:%@, imageurl:%@", result.videoId, result.imageUrl);
  313. [ZCHUDHelper showTitle:@"发布视频成功,请等待客服审核" showtime:5];
  314. dispatch_async(dispatch_get_main_queue(), ^{
  315. [weakSelf popEffectDismiss];
  316. });
  317. };
  318. OnUploadFailedListener testFailedCallbackFunc = ^(UploadFileInfo* fileInfo, NSString *code, NSString* message){
  319. NSLog(@"failed code = %@, error message = %@", code, message);
  320. // dispatch_async(dispatch_get_main_queue(), ^{
  321. // NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:0];
  322. // [weakTable reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
  323. // });
  324. };
  325. OnUploadProgressListener testProgressCallbackFunc = ^(UploadFileInfo* fileInfo, long uploadedSize, long totalSize) {
  326. NSLog(@"progress uploadedSize : %li, totalSize : %li", uploadedSize, totalSize);
  327. // UploadFileInfo* info;
  328. // int i = 0;
  329. // for(; i<[[weakClient listFiles] count]; i++) {
  330. // info = [[weakClient listFiles] objectAtIndex:i];
  331. // if (info == fileInfo) {
  332. // break;
  333. // }
  334. // }
  335. // if (nil == info) {
  336. // return;
  337. // }
  338. //
  339. // [weakList setObject:[NSString stringWithFormat:@"%ld", uploadedSize*100/totalSize] atIndexedSubscript:i];
  340. //
  341. // dispatch_async(dispatch_get_main_queue(), ^{
  342. // NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:0];
  343. // [weakTable reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic];
  344. // });
  345. };
  346. OnUploadTokenExpiredListener testTokenExpiredCallbackFunc = ^{
  347. NSLog(@"token expired.");
  348. dispatch_async(dispatch_get_main_queue(), ^{
  349. [LCHttpHelper requestWithURLString:TrendsSave parameters:@{@"videoFileName":self.youpaipvideoFileName,@"content":self.youpaipliveView.youpaiptextView.text} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  350. if (code==0) {//成功
  351. // NSString *UploadAddress = [[dict objectForKey:@"data"] objectForKey:@"UploadAddress"];
  352. NSString *UploadAuth = [[dict objectForKey:@"data"] objectForKey:@"UploadAuth"];
  353. [weakClient resumeWithAuth:UploadAuth];
  354. }
  355. } failure:^(NSError *error) {
  356. }];
  357. });
  358. };
  359. OnUploadRertyListener testRetryCallbackFunc = ^{
  360. NSLog(@"manager: retry begin.");
  361. };
  362. OnUploadRertyResumeListener testRetryResumeCallbackFunc = ^{
  363. NSLog(@"manager: retry begin.");
  364. };
  365. OnUploadStartedListener testUploadStartedCallbackFunc = ^(UploadFileInfo* fileInfo) {
  366. NSLog(@"upload started .");
  367. // Warning:每次上传都应该是独立的uploadAuth和uploadAddress
  368. // Warning:demo为了演示方便,使用了固定的uploadAuth和uploadAddress
  369. [weakClient setUploadAuthAndAddress:fileInfo uploadAuth:UploadAuth uploadAddress:UploadAddress];
  370. };
  371. VODUploadListener *listener = [[VODUploadListener alloc] init];
  372. listener.finish = testFinishCallbackFunc;
  373. listener.failure = testFailedCallbackFunc;
  374. listener.progress = testProgressCallbackFunc;
  375. listener.expire = testTokenExpiredCallbackFunc;
  376. listener.retry = testRetryCallbackFunc;
  377. listener.retryResume = testRetryResumeCallbackFunc;
  378. listener.started = testUploadStartedCallbackFunc;
  379. // 点播上传。每次上传都是独立的鉴权,所以初始化时,不需要设置鉴权
  380. // [uploader init];
  381. [self->youpaipuploader setListener:listener];
  382. // NSString *filePath = [addressDict objectForKey:@"FileName"];
  383. // NSString *ossObject = [NSString stringWithFormat:@"uploadtest/%ld.ios.demo.mp4", pos];
  384. // NSString *filePath1 = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"];
  385. //
  386. // NSLog(@"%@",filePath1);
  387. //
  388. //
  389. // NSArray *array1 = [filePath1 componentsSeparatedByString:@"://"];
  390. // NSLog(@"array:%@",array1);
  391. NSString *filePath= self.youpaipvideoFileName;
  392. NSLog(@"%@",filePath);
  393. NSArray *array = [filePath componentsSeparatedByString:@"://"];
  394. NSLog(@"array:%@",array);
  395. //
  396. // NSString *str3 = [filePath stringByReplacingOccurrencesOfString:@"file://" withString:@""];
  397. // NSLog(@"str3:%@",str3);
  398. VodInfo *vodInfo = [[VodInfo alloc] init];
  399. vodInfo.title = [NSString stringWithFormat:@"IOS标题%d", 1];
  400. vodInfo.desc = [NSString stringWithFormat:@"IOS描述%d", 1];
  401. vodInfo.cateId = @(19);
  402. // vodInfo.coverUrl = [NSString stringWithFormat:@"https://www.taobao.com/IOS封面URL%ld", pos];
  403. vodInfo.tags = [NSString stringWithFormat:@"IOS标签1%d, IOS标签2%d", 1, 1];
  404. [self->youpaipuploader addFile:[array lastObject] vodInfo:vodInfo];
  405. [self->youpaipuploader start];
  406. }
  407. } failure:^(NSError *error) {
  408. }];
  409. }
  410. }
  411. //播放视频
  412. -(void)youpaifplayVideoAction
  413. {
  414. NSString *videoPath = self.youpaipvideoFileName;
  415. if(!([videoPath rangeOfString:@"://"].location != NSNotFound))
  416. {
  417. videoPath = [NSString stringWithFormat:@"file://%@",videoPath];
  418. }
  419. NSURL * url = [NSURL URLWithString:videoPath];
  420. NSLog(@"播饭路: %@",videoPath);
  421. AVPlayerViewController *moviePlayer=[[AVPlayerViewController alloc]init];
  422. moviePlayer.player = [AVPlayer playerWithURL:url];
  423. // moviePlayer.view.frame=self.view.bounds;
  424. //
  425. // moviePlayer.view.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
  426. //
  427. // moviePlayer.showsPlaybackControls = YES;
  428. // [self.view addSubview:self.moviePlayer.view];
  429. [moviePlayer.player play];
  430. [self presentViewController:moviePlayer animated:YES completion:^{
  431. }];
  432. }
  433. - (void)youpaifopenAlbum{
  434. TZImagePickerController *imagePickerVc = [[TZImagePickerController alloc] initWithMaxImagesCount:9 columnNumber:4 delegate:nil];
  435. [LCTZImageConfigHelper setDefaultTZImageConfig:imagePickerVc];
  436. imagePickerVc.allowTakePicture = YES; // 在内部显示拍照按钮
  437. imagePickerVc.allowPickingVideo = YES;//是否允许选择视频
  438. imagePickerVc.allowPickingImage = NO;//是否允许选择照片
  439. imagePickerVc.allowPickingOriginalPhoto = NO;//是否选择原图
  440. imagePickerVc.showSelectedIndex = YES; //显示图片序号
  441. // 4. 照片排列按修改时间升序
  442. imagePickerVc.sortAscendingByModificationDate = YES;//按时间倒序排列图片
  443. // 你可以通过block或者代理,来得到用户选择的照片.
  444. __weak typeof (self) weakSelf = self;
  445. [imagePickerVc setDidFinishPickingVideoHandle:^(UIImage *coverImage, PHAsset *asset) {
  446. PHVideoRequestOptions *options = [[PHVideoRequestOptions alloc] init];
  447. options.version = PHVideoRequestOptionsVersionOriginal;
  448. options.deliveryMode = PHImageRequestOptionsDeliveryModeOpportunistic;
  449. options.networkAccessAllowed = YES;
  450. [[PHImageManager defaultManager] requestAVAssetForVideo:asset options:nil resultHandler:^(AVAsset * _Nullable asset, AVAudioMix * _Nullable audioMix, NSDictionary * _Nullable info) {
  451. AVURLAsset *urlAsser = ( AVURLAsset *)asset;
  452. NSString *videoPath =[urlAsser.URL absoluteString];
  453. NSLog(@"%@",videoPath);
  454. NSLog(@"%@",info);
  455. self.youpaipvideoFileName = videoPath;
  456. dispatch_sync(dispatch_get_main_queue(), ^{
  457. self.youpaipvideoImgView.image = coverImage;
  458. });
  459. }];
  460. }];
  461. [self presentViewController:imagePickerVc animated:YES completion:nil];
  462. }
  463. //隐藏键盘
  464. -(void)youpaifhideTheKeyboard {
  465. dispatch_async(dispatch_get_main_queue(), ^{
  466. [self.youpaipliveView.youpaiptextView endEditing:YES];
  467. });
  468. }
  469. @end