// // YOUPAIZYSendVideoByLocalVC.m // VQU // // Created by Elaine on 2020/11/9. // Copyright © 2020 leo. All rights reserved. // #import "YOUPAIZYSendVideoByLocalVC.h" #import "UIViewController+TFPresent.h" #import "YOUPAILPChatTipView.h" #import "LZAlertWindow.h" #import #import #import #import "YOUPAISHMediaManager.h"//直接裁剪类 #import "YOUPAILZTextView.h" @interface YOUPAIZYSendVideoByLocalVC () { VODUploadClient *youpaipuploader; } @property (nonatomic,strong)YOUPAILZTextView* youpaipliveView; @property(nonatomic,strong)UIImageView *youpaipvideoImgView;// @property(nonatomic,strong)UIButton *youpaipsendVideoBtn;//发布视频 @property(nonatomic,strong)UIButton *youpaipdeleBtn;//删除按钮 @property(nonatomic,strong)UIButton *youpaipplayVideoBtn;//播放按钮 @property(nonatomic,strong)UIButton *youpaipaddVideoBtn;//播放按钮 @end @implementation YOUPAIZYSendVideoByLocalVC -(void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // [self youpaifaddTip]; } - (void)youpaifaddTip{ NSString *tip = @"请勿涉及色情,广告等违规内容,违者将永久封号"; YOUPAILPChatTipView* chatTip = [[YOUPAILPChatTipView alloc]initWithFrame:CGRectMake(0,NavBarHeight-40, KScreenWidth, 40)]; chatTip.tipLabel.text = tip; [self.view addSubview:chatTip]; [UIView animateWithDuration:1 animations:^{ chatTip.frame = CGRectMake(0,NavBarHeight, KScreenWidth, 40); }completion:^(BOOL finished) { if (finished) { dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{ [UIView animateWithDuration:1 animations:^{ chatTip.frame = CGRectMake(0,NavBarHeight-40, KScreenWidth, 40); }completion:^(BOOL finished) { if (finished) { [chatTip removeFromSuperview]; } }]; }); } }]; } - (void)viewDidLoad { [super viewDidLoad]; // [self youpaifopenAlbum]; if (self.youpaipisDynamicVC) { self.title = @"视频上传"; }else{ self.title = @"本地上传"; } self.view.backgroundColor = [UIColor whiteColor]; // UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(youpaifhideTheKeyboard)]; // [self.view addGestureRecognizer:tap]; self.navigationItem.leftBarButtonItem = [UIBarButtonItem itemWithTarget:self action:@selector(youpaifcancelClick) image:[UIImage imageNamed:@"vqu_images_navigation_back_black"]]; 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"]]; YOUPAILZTextView *textView = [[YOUPAILZTextView alloc] initWithMaxCount:100]; textView.frame = CGRectMake(14.0f, 25.0f+NavBarHeight, KScreenWidth-28, 148.0f); textView.youpaiptextViewPadding = UIEdgeInsetsMake(14.0f, 14.0f, 10.0f, 14.0f); textView.youpaiptextLengthDefaultColor = LZD3D1D7Color; textView.youpaiptextLengthHigtColor = LZ7C69FEColor; textView.youpaiptextLengthFont = LCFont(14.0f); textView.youpaiptextLengthRight = 14.0f; textView.youpaiptextLengthBottom = 14.0f; textView.youpaiptextView.placeholderFont = LCFont(14.0f); textView.youpaiptextView.placeholderTextColor = LZD3D1D7Color; textView.youpaiptextView.placeholderText = @"这一刻你想说点什么…"; textView.youpaiptextView.font = LCFont(14.0f); textView.layer.cornerRadius = 5.0f; textView.clipsToBounds = YES; textView.tintColor = LZ7C69FEColor; [self.view addSubview:textView]; textView.youpaiptextView.textColor = LZ273145Color; self.youpaipliveView = textView; textView.backgroundColor = LZF7F8FAColor; UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(14.0f,CGRectGetMaxY(textView.frame)+14.0f,150,267)]; imgView.userInteractionEnabled = YES; imgView.contentMode = UIViewContentModeScaleAspectFill; imgView.layer.cornerRadius = 5.0; imgView.clipsToBounds=YES; self.youpaipvideoImgView = imgView; self.youpaipvideoImgView.image = self.youpaipcoverImage; [self.view addSubview:imgView]; //添加按钮 UIButton *addVideoBtn = [UIButton buttonWithType:UIButtonTypeCustom]; addVideoBtn.frame = CGRectMake(14.0f,CGRectGetMaxY(textView.frame)+14.0f,173,230); [addVideoBtn setImage:[UIImage imageNamed:@"vqu_images_D_dynamic_New_add"] forState:0]; [addVideoBtn addTarget:self action:@selector(youpaifAddNewVideoClick) forControlEvents:UIControlEventTouchUpInside]; [self.view addSubview:addVideoBtn]; self.youpaipaddVideoBtn = addVideoBtn; addVideoBtn.hidden = YES; UIButton *playVideoBtn = [UIButton buttonWithType:UIButtonTypeCustom]; playVideoBtn.frame = CGRectMake(50,105,50,50); [playVideoBtn setImage:[UIImage imageNamed:@"vqu_images_D_video_play"] forState:0]; [playVideoBtn addTarget:self action:@selector(youpaifplayVideoAction) forControlEvents:UIControlEventTouchUpInside]; [imgView addSubview:playVideoBtn]; self.youpaipplayVideoBtn = playVideoBtn; //删除按钮 UIButton *deleBtn = [[UIButton alloc]initWithFrame:CGRectMake(CGRectGetMaxX(imgView.frame)-38, 8, 20, 20)]; [deleBtn setImage:[UIImage imageNamed:@"vqu_images_D_dynamic_dele"] forState:UIControlStateNormal]; self.youpaipdeleBtn = deleBtn; [deleBtn addTarget:self action:@selector(youpaifdeleVideoAction) forControlEvents:UIControlEventTouchUpInside]; [imgView addSubview:deleBtn]; self.youpaipsendVideoBtn = [UIButton buttonWithType:UIButtonTypeCustom]; self.youpaipsendVideoBtn.frame = CGRectMake(40.0f,KScreenHeight-77-SafeHeight,KScreenWidth - 80.0f,48); [self.youpaipsendVideoBtn setTitle:@"发布视频" forState:0]; [self.youpaipsendVideoBtn setTitleColor:HexColorFromRGB(0xFFFFFF) forState:0]; self.youpaipsendVideoBtn.titleLabel.font = LCFont(16); self.youpaipsendVideoBtn.layer.cornerRadius = 24; self.youpaipsendVideoBtn.layer.masksToBounds = YES; [self.youpaipsendVideoBtn addTarget:self action:@selector(youpaifsendClick) forControlEvents:UIControlEventTouchUpInside]; [self.youpaipsendVideoBtn setBackgroundImage:[LCTools ColorImage:self.youpaipsendVideoBtn.frame.size FromColors:@[LZBFB6FFColor,LZ7C69FEColor] ByGradientType:(GradientLeftToRight)] forState:(UIControlStateNormal)]; [self.view addSubview:self.youpaipsendVideoBtn]; youpaipuploader = [VODUploadClient new]; } //删除 -(void)youpaifdeleVideoAction{ self.youpaipdeleBtn.hidden = YES; self.youpaipplayVideoBtn.hidden = YES; self.youpaipvideoFileName = nil; [UIView animateWithDuration:0.1 animations:^{ self.youpaipvideoImgView.hidden = YES; self.youpaipaddVideoBtn.hidden = NO; }]; } -(void)youpaifAddNewVideoClick{ 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或者代理,来得到用户选择的照片. @weakify(self); [imagePickerVc setDidFinishPickingVideoHandle:^(UIImage *coverImage, PHAsset *asset) { @strongify(self); 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]; if (asset == nil) { [ZCHUDHelper showTitle:@"无效视频"]; return; } 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]; self.youpaipvideoImgView.image = coverImage; self.youpaipvideoFileName = videoPath; self.youpaipdeleBtn.hidden = NO; self.youpaipplayVideoBtn.hidden = NO; [UIView animateWithDuration:0.1 animations:^{ self.youpaipaddVideoBtn.hidden = YES; self.youpaipvideoImgView.hidden = NO; }]; } }); }]; }]; [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:@"裁剪完成"]; self.youpaipvideoImgView.image = coverImage; self.youpaipvideoFileName = videoPath; self.youpaipdeleBtn.hidden = NO; self.youpaipplayVideoBtn.hidden = NO; [UIView animateWithDuration:0.1 animations:^{ self.youpaipaddVideoBtn.hidden = YES; self.youpaipvideoImgView.hidden = NO; }]; }); }); }else{ [ZCHUDHelper showTitle:@"裁剪失败"]; } }]; }]; [alertController addAction:cancelAction]; [alertController addAction:okAction]; [self presentViewController:alertController animated:YES completion:nil]; } - (void)youpaifcancelClick{ [self popEffectDismiss]; // self.sendModel.tit = self.liveView.textView.text; // UIAlertController *alertController = [UIAlertController alertControllerWithTitle:nil message:@"要保存草稿吗?" preferredStyle:UIAlertControllerStyleAlert]; // UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"放弃" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){ // // [LCSaveModel saveSendDynamicModel:nil]; // [self popEffectDismiss]; // }]; // UIAlertAction *okAction = [UIAlertAction actionWithTitle:@"保存" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action){ // // [LCSaveModel saveSendDynamicModel:self.sendModel]; // [self popEffectDismiss]; // }]; // [alertController addAction:cancelAction]; // [alertController addAction:okAction]; // [self presentViewController:alertController animated:YES completion:nil]; } //提示 -(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)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{ [self youpaifhideTheKeyboard]; } //发布视频 -(void)youpaifsendClick { if (self.youpaipliveView.youpaiptextView.text.length == 0) { [ZCHUDHelper showTitle:@"文字不能为空"]; return; } if (self.youpaipvideoFileName == nil) { [ZCHUDHelper showTitle:@"请选择视频"]; return; } __weak VODUploadClient *weakClient = youpaipuploader; __weak YOUPAIZYSendVideoByLocalVC *weakSelf = self; if (self.youpaipisDynamicVC) { [LCHttpHelper requestWithURLString:DynamicPub parameters:@{@"videoFileName":self.youpaipvideoFileName,@"content":self.youpaipliveView.youpaiptextView.text,@"type":@"1"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSString* dynamicId = [[dict objectForKey:@"data"]objectForKey:@"dynamic_id"]; [ZCHUDHelper show]; [LCCommonHttp uploadWithVideoPath:self.youpaipvideoFileName Type:@"dynamic" successBlock:^(NSString *ossFilePath) { [LCHttpHelper requestWithURLString:DynamicUpdateImage parameters:@{@"images":ossFilePath, @"dynamic_id":dynamicId, @"type":@"1"} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) { [LCSaveModel saveSendDynamicModel:nil]; } [ZCHUDHelper dismiss]; [self popEffectDismiss]; } failure:^(NSError *error) { [ZCHUDHelper dismiss]; [ZCHUDHelper showTitle:@"发布失败"]; [self popEffectDismiss]; }]; }]; } } failure:^(NSError *error) { }]; } else{ [LCHttpHelper requestWithURLString:TrendsSave parameters:@{@"videoFileName":self.youpaipvideoFileName,@"content":self.youpaipliveView.youpaiptextView.text} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { NSDictionary* dict = (NSDictionary*)responseObject; NSInteger code = [[dict objectForKey:@"code"] integerValue]; if (code==0) {//成功 NSString *UploadAddress = [[dict objectForKey:@"data"] objectForKey:@"UploadAddress"]; NSString *UploadAuth = [[dict objectForKey:@"data"] objectForKey:@"UploadAuth"]; // NSString *VideoId = [[dict objectForKey:@"data"] objectForKey:@"VideoId"]; // NSString *RequestId = [[dict objectForKey:@"data"] objectForKey:@"RequestId"]; // callback functions and listener OnUploadFinishedListener testFinishCallbackFunc = ^(UploadFileInfo* fileInfo, VodUploadResult* result){ NSLog(@"wz on upload finished videoid:%@, imageurl:%@", result.videoId, result.imageUrl); [ZCHUDHelper showTitle:@"发布视频成功,请等待客服审核" showtime:5]; dispatch_async(dispatch_get_main_queue(), ^{ [weakSelf popEffectDismiss]; }); }; OnUploadFailedListener testFailedCallbackFunc = ^(UploadFileInfo* fileInfo, NSString *code, NSString* message){ NSLog(@"failed code = %@, error message = %@", code, message); // dispatch_async(dispatch_get_main_queue(), ^{ // NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:0]; // [weakTable reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic]; // }); }; OnUploadProgressListener testProgressCallbackFunc = ^(UploadFileInfo* fileInfo, long uploadedSize, long totalSize) { NSLog(@"progress uploadedSize : %li, totalSize : %li", uploadedSize, totalSize); // UploadFileInfo* info; // int i = 0; // for(; i<[[weakClient listFiles] count]; i++) { // info = [[weakClient listFiles] objectAtIndex:i]; // if (info == fileInfo) { // break; // } // } // if (nil == info) { // return; // } // // [weakList setObject:[NSString stringWithFormat:@"%ld", uploadedSize*100/totalSize] atIndexedSubscript:i]; // // dispatch_async(dispatch_get_main_queue(), ^{ // NSIndexSet *indexSet=[[NSIndexSet alloc]initWithIndex:0]; // [weakTable reloadSections:indexSet withRowAnimation:UITableViewRowAnimationAutomatic]; // }); }; OnUploadTokenExpiredListener testTokenExpiredCallbackFunc = ^{ NSLog(@"token expired."); dispatch_async(dispatch_get_main_queue(), ^{ [LCHttpHelper requestWithURLString:TrendsSave parameters:@{@"videoFileName":self.youpaipvideoFileName,@"content":self.youpaipliveView.youpaiptextView.text} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) { if (code==0) {//成功 // NSString *UploadAddress = [[dict objectForKey:@"data"] objectForKey:@"UploadAddress"]; NSString *UploadAuth = [[dict objectForKey:@"data"] objectForKey:@"UploadAuth"]; [weakClient resumeWithAuth:UploadAuth]; } } failure:^(NSError *error) { }]; }); }; OnUploadRertyListener testRetryCallbackFunc = ^{ NSLog(@"manager: retry begin."); }; OnUploadRertyResumeListener testRetryResumeCallbackFunc = ^{ NSLog(@"manager: retry begin."); }; OnUploadStartedListener testUploadStartedCallbackFunc = ^(UploadFileInfo* fileInfo) { NSLog(@"upload started ."); // Warning:每次上传都应该是独立的uploadAuth和uploadAddress // Warning:demo为了演示方便,使用了固定的uploadAuth和uploadAddress [weakClient setUploadAuthAndAddress:fileInfo uploadAuth:UploadAuth uploadAddress:UploadAddress]; }; VODUploadListener *listener = [[VODUploadListener alloc] init]; listener.finish = testFinishCallbackFunc; listener.failure = testFailedCallbackFunc; listener.progress = testProgressCallbackFunc; listener.expire = testTokenExpiredCallbackFunc; listener.retry = testRetryCallbackFunc; listener.retryResume = testRetryResumeCallbackFunc; listener.started = testUploadStartedCallbackFunc; // 点播上传。每次上传都是独立的鉴权,所以初始化时,不需要设置鉴权 // [uploader init]; [self->youpaipuploader setListener:listener]; // NSString *filePath = [addressDict objectForKey:@"FileName"]; // NSString *ossObject = [NSString stringWithFormat:@"uploadtest/%ld.ios.demo.mp4", pos]; // NSString *filePath1 = [[NSBundle mainBundle] pathForResource:@"video" ofType:@"mp4"]; // // NSLog(@"%@",filePath1); // // // NSArray *array1 = [filePath1 componentsSeparatedByString:@"://"]; // NSLog(@"array:%@",array1); NSString *filePath= self.youpaipvideoFileName; NSLog(@"%@",filePath); NSArray *array = [filePath componentsSeparatedByString:@"://"]; NSLog(@"array:%@",array); // // NSString *str3 = [filePath stringByReplacingOccurrencesOfString:@"file://" withString:@""]; // NSLog(@"str3:%@",str3); VodInfo *vodInfo = [[VodInfo alloc] init]; vodInfo.title = [NSString stringWithFormat:@"IOS标题%d", 1]; vodInfo.desc = [NSString stringWithFormat:@"IOS描述%d", 1]; vodInfo.cateId = @(19); // vodInfo.coverUrl = [NSString stringWithFormat:@"https://www.taobao.com/IOS封面URL%ld", pos]; vodInfo.tags = [NSString stringWithFormat:@"IOS标签1%d, IOS标签2%d", 1, 1]; [self->youpaipuploader addFile:[array lastObject] vodInfo:vodInfo]; [self->youpaipuploader start]; } } failure:^(NSError *error) { }]; } } //播放视频 -(void)youpaifplayVideoAction { NSString *videoPath = self.youpaipvideoFileName; if(!([videoPath rangeOfString:@"://"].location != NSNotFound)) { videoPath = [NSString stringWithFormat:@"file://%@",videoPath]; } NSURL * url = [NSURL URLWithString:videoPath]; NSLog(@"播饭路: %@",videoPath); AVPlayerViewController *moviePlayer=[[AVPlayerViewController alloc]init]; moviePlayer.player = [AVPlayer playerWithURL:url]; // moviePlayer.view.frame=self.view.bounds; // // moviePlayer.view.autoresizingMask=UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; // // moviePlayer.showsPlaybackControls = YES; // [self.view addSubview:self.moviePlayer.view]; [moviePlayer.player play]; [self presentViewController:moviePlayer animated:YES completion:^{ }]; } - (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或者代理,来得到用户选择的照片. __weak typeof (self) weakSelf = self; [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); self.youpaipvideoFileName = videoPath; dispatch_sync(dispatch_get_main_queue(), ^{ self.youpaipvideoImgView.image = coverImage; }); }]; }]; [self presentViewController:imagePickerVc animated:YES completion:nil]; } //隐藏键盘 -(void)youpaifhideTheKeyboard { dispatch_async(dispatch_get_main_queue(), ^{ [self.youpaipliveView.youpaiptextView endEditing:YES]; }); } @end