VideoDynamicViewC.m 38 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860
  1. //
  2. // VideoDynamicViewC.m
  3. // BuguLive
  4. //
  5. // Created by 岳克奎 on 17/4/17.
  6. // Copyright © 2017年 xfg. All rights reserved.
  7. //
  8. #import "VideoDynamicViewC.h"
  9. #import <AssetsLibrary/ALAsset.h>
  10. #import <AssetsLibrary/ALAssetsLibrary.h>
  11. #import <AssetsLibrary/ALAssetsGroup.h>
  12. #import <AssetsLibrary/ALAssetRepresentation.h>
  13. #import <Photos/Photos.h>
  14. #import <MediaPlayer/MediaPlayer.h>
  15. #import "UIImage+STCommon.h"
  16. #import "VideoCoverViewC.h"
  17. #import "STVideoCoverLayout.h"
  18. #import "VideoCateVC.h"
  19. #import "DTTopicModel.h"
  20. #import "BGTCUploadHelp.h"
  21. #import "BogoShopKit.h"
  22. #import "BogoNetwork.h"
  23. #import "BogoVideoShopAddViewController.h"
  24. @interface VideoDynamicViewC ()
  25. {
  26. NSTimer *_imageTimer; //上传视频的定时器
  27. int _timeCount; //上传视频的时间超过三分钟就报超时
  28. NSString *imageUrl;
  29. NSString *videoUrl;
  30. }
  31. @property(nonatomic, strong) NSString *audioTime;
  32. @property(nonatomic, strong) NSString *selectedTopicID;
  33. @property(nonatomic, strong) BogoCommodityDetailShopModel *shopModel;
  34. @property(nonatomic, strong) NSMutableArray *cateArray;
  35. @property(nonatomic, assign) CGSize videoSize;
  36. @end
  37. @implementation VideoDynamicViewC
  38. - (void)viewDidLoad
  39. {
  40. [super viewDidLoad];
  41. [self.navigationController setNavigationBarHidden:YES animated:NO];
  42. self.navigationController.navigationBarHidden = YES;
  43. UIImageView *topImgView = [[UIImageView alloc]initWithFrame:CGRectMake(0, 0, kScreenW, SCREEN_HEIGHT)];
  44. topImgView.image = [UIImage imageNamed:@"mainBg"];
  45. [self.view addSubview:topImgView];
  46. UIView * navView = [[UIView alloc] initWithFrame:CGRectMake(0, StatusBarHeight, SCREEN_WIDTH, NavigationHeight)];
  47. navView.backgroundColor = UIColor.clearColor;
  48. [self.view addSubview:navView];
  49. UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  50. [backBtn setImage:[UIImage imageNamed:@"com_arrow_vc_back"] forState:UIControlStateNormal];
  51. backBtn.frame = CGRectMake(10, 0, 44, 44);
  52. [backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
  53. [navView addSubview:backBtn];
  54. UILabel * titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 200, 30)];
  55. titleLabel.centerX = SCREEN_WIDTH/2;
  56. titleLabel.centerY = backBtn.centerY;
  57. titleLabel.text = ASLocalizedString(@"发布短视频");
  58. titleLabel.textColor = UIColor.blackColor;
  59. titleLabel.font = [UIFont boldSystemFontOfSize:18];
  60. titleLabel.textAlignment = NSTextAlignmentCenter;
  61. [navView addSubview:titleLabel];
  62. // [self ossManager];
  63. _timeCount = 180000;
  64. self.selectedTopicID = @"";
  65. // [[UIBarButtonItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:kClearColor,
  66. // NSFontAttributeName:[UIFont systemFontOfSize:20.0]
  67. // } forState:UIControlStateNormal];
  68. // self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithImage:[UIImage imageNamed:@"com_arrow_vc_back"] style:UIBarButtonItemStylePlain target:self action:@selector(backBtnAction)];
  69. // UIButton * backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
  70. // [backBtn setImage:[UIImage imageNamed:@"com_arrow_vc_back"] forState:UIControlStateNormal];
  71. // backBtn.frame = CGRectMake(10, 0, 44, 44);
  72. // [backBtn addTarget:self action:@selector(backBtnAction) forControlEvents:UIControlEventTouchUpInside];
  73. // self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backBtn];
  74. [self requestCateData];
  75. }
  76. - (void)backBtnAction{
  77. if (self.presentingViewController) {
  78. [self dismissViewControllerAnimated:YES completion:nil];
  79. }else{
  80. [self.navigationController popViewControllerAnimated:YES];
  81. }
  82. }
  83. - (void)viewWillAppear:(BOOL)animated
  84. {
  85. [super viewWillAppear:animated];
  86. [self.navigationController setNavigationBarHidden:YES animated:YES];
  87. self.navigationController.navigationBarHidden = YES;
  88. // // self.navigationController.view.backgroundColor = kRedColor;
  89. //
  90. //
  91. // self.navigationController.navigationBar.hidden = NO;
  92. // self.navigationController.title = ASLocalizedString(@"发布短视频");
  93. // self.navigationController.navigationBar.tintColor =kAppGrayColor1;
  94. //
  95. //
  96. // [[UIBarButtonItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:kClearColor,
  97. // NSFontAttributeName:[UIFont systemFontOfSize:20.0]
  98. // } forState:UIControlStateNormal];
  99. }
  100. - (void)viewDidAppear:(BOOL)animated {
  101. [super viewDidAppear:animated];
  102. self.navigationController.navigationBar.hidden = YES;
  103. // self.navigationController.title = ASLocalizedString(@"发布短视频");
  104. // self.navigationController.navigationBar.tintColor =kAppGrayColor1;
  105. //
  106. // [[UIBarButtonItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:kClearColor,
  107. // NSFontAttributeName:[UIFont systemFontOfSize:20.0]
  108. // } forState:UIControlStateNormal];
  109. }
  110. - (void)viewWillDisappear:(BOOL)animated {
  111. [super viewWillDisappear:animated];
  112. // self.navigationController.navigationBar.hidden = YES;
  113. self.navigationController.title = ASLocalizedString(@"发布短视频");
  114. self.navigationController.navigationBar.tintColor =kAppGrayColor1;
  115. [[UIBarButtonItem appearance]setTitleTextAttributes:@{NSForegroundColorAttributeName:kBlackColor,
  116. NSFontAttributeName:[UIFont systemFontOfSize:15]
  117. } forState:UIControlStateNormal];
  118. }
  119. -(VideoDynamicView *)videoDynamicView{
  120. if (!_videoDynamicView) {
  121. _videoDynamicView = (VideoDynamicView *)[VideoDynamicView showSTBaseViewOnSuperView:self.view
  122. loadNibNamedStr:@"VideoDynamicView"
  123. andFrameRect:CGRectMake(0, NavigationHeight, kScreenW, kScreenH - TabBarHeight - NavigationHeight)
  124. andComplete:^(BOOL finished,
  125. STBaseView *stBaseView) {
  126. }];
  127. [_videoDynamicView setBaseDelegate:self];
  128. [_videoDynamicView setDelegate:self];
  129. // _videoDynamicView.tableView.tableFooterView = [UIView new];
  130. _videoDynamicView.tableView.mj_footer.hidden = YES;
  131. _videoDynamicView.tableView.backgroundColor = UIColor.clearColor;
  132. }
  133. return _videoDynamicView;
  134. }
  135. - (void)requestCateData{
  136. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  137. [parmDict setObject:@"dynamic" forKey:@"ctl"];
  138. [parmDict setObject:@"dynamic_cate" forKey:@"act"];
  139. [[NetHttpsManager manager] POSTWithParameters:parmDict SuccessBlock:^(NSDictionary *responseJson) {
  140. NSArray * array = responseJson[@"data"];
  141. [self.cateArray removeAllObjects];
  142. for (id obj in array)
  143. {
  144. DTTopicModel *model =[DTTopicModel mj_objectWithKeyValues:obj];
  145. [self.cateArray addObject:model];
  146. }
  147. // [self.tableView reloadData];
  148. } FailureBlock:^(NSError *error) {
  149. }];
  150. }
  151. -(void)upLoadVideoUrl:(NSString *)urls{
  152. NSURL *url = [NSURL fileURLWithPath:urls];
  153. AVURLAsset *asset1 = [AVURLAsset assetWithURL:url];
  154. CMTime time = [asset1 duration];
  155. int seconds = ceil(time.value/time.timescale);
  156. self.audioTime = [NSString stringWithFormat:@"%d",seconds];
  157. #pragma mark - 帧图数据
  158. NSMutableArray *tempImageMArray =@[].mutableCopy;
  159. NSLog(@"VideoDynamicView1111");
  160. FWWeakify(self)
  161. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  162. NSLog(@"VideoDynamicView2222");
  163. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  164. //数组 专门存
  165. //GCD 快速遍历
  166. NSLog(@"-----------se-----%d",seconds);
  167. if(!self.videoMArray)
  168. {
  169. self.videoMArray = @[].mutableCopy;
  170. }
  171. //只保留一个视频
  172. [self.videoMArray removeAllObjects];
  173. NSLog(@"VideoDynamicView3333");
  174. @autoreleasepool {
  175. // [self movFileTransformToMP4WithSourceUrl:url completion:^(NSURL *Mp4FilePath) {
  176. NSData *videoData = [NSData dataWithContentsOfURL:url];
  177. [self.videoMArray addObject:videoData];
  178. NSLog(@"videoMArray%ld",self.videoMArray.count);
  179. NSLog(@"VideoDynamicView4444");
  180. // for (int i = 0;i< seconds;i++) {
  181. UIImage *thumbnailImage = [UIImage st_thumbnailImageForVideo:url atTime:0];
  182. [tempImageMArray addObject:thumbnailImage];
  183. // }
  184. //
  185. dispatch_async(dispatch_get_main_queue(), ^{
  186. NSLog(@"VideoDynamicView5555");
  187. //下发 帧图数组
  188. FWStrongify(self)
  189. [self showSelectedMAray:tempImageMArray];
  190. self.videoDynamicView.videoURL = url;
  191. // [self.navigationController popViewControllerAnimated:YES];
  192. });
  193. }
  194. });
  195. }
  196. #pragma ********************************* 子重写父 方法区域 *************************
  197. #pragma mark - 系统 -完成照片选择回调
  198. - (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
  199. //获取 选择的类型
  200. NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
  201. //这里只选择 视频
  202. if ([mediaType isEqualToString:@"public.movie"]) {
  203. //获取视图的url
  204. NSURL *url = [info objectForKey:UIImagePickerControllerMediaURL];
  205. AVURLAsset * asset1 = [AVURLAsset assetWithURL:url];
  206. CMTime time = [asset1 duration];
  207. int seconds = ceil(time.value/time.timescale);
  208. //多帧图
  209. // MPMoviePlayerController *moviePlayer = [[MPMoviePlayerController alloc] initWithContentURL:url];
  210. // moviePlayer.shouldAutoplay = NO;
  211. if ((int)seconds <3) {
  212. [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"选取视频时长太小")];
  213. //关闭当前的模态视图
  214. [self dismissViewControllerAnimated:YES completion:^{
  215. [self.navigationController popViewControllerAnimated:YES];
  216. }];
  217. return;
  218. }else if((int)seconds >=[[GlobalVariables sharedInstance].appModel.sts_video_limit floatValue]) {
  219. [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"选取视频时长太大")];
  220. //关闭当前的模态视图
  221. [self dismissViewControllerAnimated:YES completion:^{
  222. [self.navigationController popViewControllerAnimated:YES];
  223. }];
  224. return;
  225. }else{
  226. }
  227. self.videoSize = [[[asset1 tracksWithMediaType:AVMediaTypeVideo] objectAtIndex:0] naturalSize];
  228. #pragma mark - 帧图数据
  229. NSMutableArray *tempImageMArray =@[].mutableCopy;
  230. dispatch_async(dispatch_get_global_queue(0, 0), ^{
  231. dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
  232. //数组 专门存
  233. //GCD 快速遍历
  234. NSLog(@"-----------se-----%d",seconds);
  235. if(!self.videoMArray)
  236. {
  237. self.videoMArray = @[].mutableCopy;
  238. }
  239. //只保留一个视频
  240. [self.videoMArray removeAllObjects];
  241. @autoreleasepool {
  242. [self movFileTransformToMP4WithSourceUrl:url completion:^(NSURL *Mp4FilePath) {
  243. NSData *videoData = [NSData dataWithContentsOfURL:Mp4FilePath];
  244. self.videoDynamicView.videoURL = Mp4FilePath;
  245. [self.videoMArray addObject:videoData];
  246. for (int i = 0;i< seconds;i++) {
  247. UIImage *thumbnailImage = [UIImage st_thumbnailImageForVideo:Mp4FilePath atTime:i];
  248. [tempImageMArray addObject:thumbnailImage];
  249. }
  250. dispatch_async(dispatch_get_main_queue(), ^{
  251. //下发 帧图数组
  252. [self showSelectedMAray:tempImageMArray];
  253. //关闭当前的模态视图
  254. [self dismissViewControllerAnimated:YES completion:^{
  255. [self popoverPresentationController];
  256. }];
  257. });
  258. }];
  259. }
  260. });
  261. }
  262. }
  263. #pragma - 系统imgPickerC - 取消按钮
  264. - (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker{
  265. [self dismissViewControllerAnimated:YES
  266. completion:^{
  267. }];
  268. if (self.videoDynamicView.dataSoureMArray.count == 0) {
  269. [[AppDelegate sharedAppDelegate] popViewController];
  270. }
  271. }
  272. #pragma mark -----IPC数据下发(子重写)
  273. -(void)showSelectedMAray:(NSMutableArray *)selectedMArray{
  274. NSLog(@"-----3131------%lu----------",(unsigned long)selectedMArray.count);
  275. [self videoDynamicView];
  276. self.videoDynamicView.dataSoureMArray = selectedMArray;
  277. NSLog(@"-----------------%@",NSStringFromClass([selectedMArray[0] class]));
  278. //本地服务器缩略图
  279. // if([GlobalVariables sharedInstance].appModel.open_sts != 1 || ([[GlobalVariables sharedInstance].appModel.short_video_store isEqualToString:@"1"]))
  280. // {
  281. NSArray*paths =NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
  282. NSString*filePath = [paths[0] stringByAppendingPathComponent:[NSString stringWithFormat:@"demo.png"]];// 保存文件的名称
  283. BOOL result =[UIImagePNGRepresentation(selectedMArray[0]) writeToFile:filePath atomically:YES];// 保存成功会返回YES
  284. if(result ==YES) {
  285.    NSLog(ASLocalizedString(@"保存成功"));
  286. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  287. [parmDict setObject:@"upload_file" forKey:@"ctl"];
  288. [parmDict setObject:@"upload_video_file" forKey:@"act"];
  289. [[NetHttpsManager manager] POSTWithDict:parmDict andFileUrl:[NSURL fileURLWithPath:filePath] SuccessBlock:^(NSDictionary *responseJson) {
  290. self.recordVideoCoverURLStr = responseJson[@"server_full_path"];
  291. } FailureBlock:^(NSError *error) {
  292. }];
  293. }
  294. else
  295. {
  296. [BGHUDHelper alert:ASLocalizedString(@"图片保存失败")];
  297. }
  298. // }
  299. [self.videoDynamicView.tableView reloadData];
  300. }
  301. #pragma ********************************* Delegate 代理 *************************
  302. #pragma -------------- <STTableViewBaseViewDelegate>
  303. -(void)showTableViewDidSelectIndexpath:(NSIndexPath *)indexPath andSTTableBaseView:(STTableBaseView *)stTableBaseView{
  304. if (indexPath.section == 3 && indexPath.row == 0)
  305. {
  306. [self showPublishDynamic];
  307. }
  308. //百度地图定位
  309. if(indexPath.section == 2 && indexPath.row == 0)
  310. {
  311. //加载地图
  312. [self showSTBMKViewC];
  313. }
  314. }
  315. #pragma ************************* 地图部分 *************************
  316. /*
  317. //百度地图定位
  318. if(indexPath.section == 2 && indexPath.row == 0){
  319. //加载地图
  320. [self showSTBMKViewC];
  321. }
  322. }*/
  323. #pragma -------------刷新 地图选择
  324. // 因为父层去拿子层的View,好难 那就重写
  325. -(void)showUpdateLoactionInfoOfIndexPath
  326. {
  327. NSIndexPath *indexPath=[NSIndexPath indexPathForRow:0 inSection:2];
  328. [self.videoDynamicView.tableView reloadRowsAtIndexPaths:[NSArray arrayWithObjects:indexPath,nil]
  329. withRowAnimation:UITableViewRowAnimationNone];
  330. }
  331. #pragma mark ---------- 发布(子重写)
  332. //(为了统一,所有发布方法一致)
  333. -(void)showPublishDynamic
  334. {
  335. //
  336. [self videoDynamicView];
  337. //1区0行 -动态文本
  338. if(!self.videoDynamicView.recordTextViewStr
  339. ||self.videoDynamicView.recordTextViewStr.length<1
  340. ||[self.videoDynamicView.recordTextViewStr isEqualToString:ASLocalizedString(@"这一刻你的想法")]){
  341. [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"请编辑这一刻你的想法")];
  342. return;
  343. }
  344. //位置
  345. //帧图要存在
  346. //视频是否存在
  347. if (self.videoMArray.count == 0)
  348. {
  349. [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"视频数据不小心丢失了,请重新选择")];
  350. return;
  351. }
  352. // 数据预处理
  353. NSMutableArray <NSData *>*tempImgDataMArray = @[].mutableCopy;
  354. //处理帧图数据
  355. UIImage *image = self.videoDynamicView.dataSoureMArray[self.videoDynamicView.recordSelectIndex];
  356. [tempImgDataMArray addObject:UIImagePNGRepresentation(image)];
  357. //帧图存在
  358. if(tempImgDataMArray.count== 0)
  359. {
  360. [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"帧图数据不小心丢失了,请重新选择")];
  361. return;
  362. }
  363. //开启上传
  364. // if (![self.ossManager isSetRightParameter])
  365. // {
  366. // [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"图片参数配置失败")];
  367. // return;
  368. // }
  369. FWWeakify(self);
  370. if (!_imageTimer)
  371. {
  372. _imageTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(imageTimeGo) userInfo:nil repeats:YES];
  373. [[NSRunLoop currentRunLoop] addTimer:_imageTimer forMode:NSDefaultRunLoopMode];
  374. }
  375. [[BGHUDHelper sharedInstance]syncLoading:ASLocalizedString(@"正在上传数据中...")];
  376. //这个地方之前写错了
  377. /** 本地 **/
  378. // if([[GlobalVariables sharedInstance].appModel.short_video_store isEqualToString:@"2"])
  379. // {
  380. NSMutableDictionary *parmDict = [NSMutableDictionary dictionary];
  381. [parmDict setObject:@"upload_file" forKey:@"ctl"];
  382. [parmDict setObject:@"upload_video_file" forKey:@"act"];
  383. [[NetHttpsManager manager] POSTWithDict:parmDict andFileUrl:self.videoDynamicView.videoURL SuccessBlock:^(NSDictionary *responseJson) {
  384. self.recordVideoURLStr = responseJson[@"server_full_path"];
  385. [[BGHUDHelper sharedInstance]syncStopLoading];
  386. [[BGHUDHelper sharedInstance]syncLoading:ASLocalizedString(@"正在发布中...")];
  387. [self showHttpServiceublishDynamic];
  388. } FailureBlock:^(NSError *error) {
  389. }];
  390. // }
  391. /** 阿里云 **/
  392. // else if([[GlobalVariables sharedInstance].appModel.short_video_store isEqualToString:@"0"])
  393. // {
  394. // [self.ossManager showUploadOfOssServiceOfDataMarray:tempImgDataMArray
  395. // andSTDynamicSelectType:STDynamicSelectPhoto
  396. // andComplete:^(BOOL finished,
  397. // NSMutableArray<NSString *> *urlStrMArray) {
  398. // FWStrongify(self)
  399. // if (urlStrMArray.count>0)
  400. // {
  401. // //图片url str
  402. // self.recordVideoCoverURLStr = urlStrMArray[0];
  403. // //任务2:上传 视频 MOC 格式
  404. // // [[BGHUDHelper sharedInstance]syncLoading:ASLocalizedString(@"正在上传数据中...")];
  405. //
  406. // [self.ossManager showUploadOfOssServiceOfDataMarray:self.videoMArray
  407. // andSTDynamicSelectType:STDynamicSelectVideo
  408. // andComplete:^(BOOL finished,
  409. // NSMutableArray<NSString *> *urlStrMArray) {
  410. // [[BGHUDHelper sharedInstance]syncStopLoading];
  411. // if(urlStrMArray.count>0)
  412. // {
  413. // self.recordVideoURLStr = urlStrMArray[0];
  414. // [[BGHUDHelper sharedInstance]syncLoading:ASLocalizedString(@"正在发布中...")];
  415. // [self showHttpServiceublishDynamic];
  416. // }
  417. // }];
  418. //
  419. //
  420. //
  421. //
  422. // }
  423. //
  424. // }];
  425. // }
  426. /** 腾讯云 **/
  427. // else if([[GlobalVariables sharedInstance].appModel.short_video_store isEqualToString:@"1"])
  428. // {
  429. //
  430. //
  431. // @weakify(self)
  432. //
  433. // [[BGTCUploadHelp sharedBGTCUploadHelp] uploadVideoWithVideoPath:self.videoDynamicView.videoURL.path];
  434. // [BGTCUploadHelp sharedBGTCUploadHelp].publishResult = ^(BOOL success, NSString * _Nonnull recordVideoURLStr, NSString * _Nonnull msg) {
  435. // [[BGHUDHelper sharedInstance]syncStopLoading];
  436. //
  437. // if(success)
  438. // {
  439. //
  440. //
  441. // weak_self.recordVideoURLStr = recordVideoURLStr;
  442. // [[BGHUDHelper sharedInstance]syncLoading:ASLocalizedString(@"正在发布中...")];
  443. // [weak_self showHttpServiceublishDynamic];
  444. // }
  445. //
  446. //
  447. // };
  448. // }
  449. }
  450. - (void)imageTimeGo
  451. {
  452. _timeCount --;
  453. NSLog(@"timeCount===%d",_timeCount);
  454. if (_timeCount == 0)
  455. {
  456. [_imageTimer invalidate];
  457. _imageTimer = nil;
  458. [[BGHUDHelper sharedInstance]syncStopLoading];
  459. [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"视频上传超时")];
  460. }
  461. }
  462. #pragma----正式提交服务器 发布
  463. -(void)showHttpServiceublishDynamic{
  464. if(self.recordVideoCoverURLStr == nil)
  465. {
  466. [BGHUDHelper alert:ASLocalizedString(@"封面图未上传完")];
  467. return;
  468. }
  469. if(self.recordVideoURLStr == nil)
  470. {
  471. [BGHUDHelper alert:ASLocalizedString(@"视频未上传完")];
  472. return;
  473. }
  474. //地图管理类
  475. STBMKCenter *stBMKCenter = [STBMKCenter shareManager];
  476. //参数MDic
  477. // @"api/liveAddGoodsUrl" param:@{@"token":[BogoNetwork shareInstance].token
  478. // @"ctl":@"publish",@"act":@"do_publish"
  479. NSMutableDictionary *parametersMDic = @{@"ctl" :@"weibo",
  480. @"act" :@"release",
  481. @"itype" :@"xr",
  482. @"type" :@"video",
  483. @"cate" :self.selectedTopicID, // 发布商品
  484. @"content" :self.videoDynamicView.recordTextViewStr, // 动态文本
  485. @"photo_image" :self.recordVideoCoverURLStr, // OSS 封面图 URL
  486. @"video_url" :self.recordVideoURLStr, // OSS 视频 URL
  487. @"latitude" :@(stBMKCenter.latitudeValue), // 纬度值
  488. @"longitude" :@(stBMKCenter.longitudeValue), // 经度值
  489. @"city" :stBMKCenter.cityNameStr, // 城市名称
  490. @"province" :stBMKCenter.provinceStr, // 省会
  491. @"address" :stBMKCenter.detailAdressStr, // 具体坐标地址
  492. @"shop_title":SafeStr(self.shopModel.shop_title),
  493. @"shop_id":SafeStr(self.shopModel.gid),
  494. @"width":@(self.videoSize.width),
  495. @"height":@(self.videoSize.height),
  496. @"video_direction":self.videoSize.width > self.videoSize.height ? @"1" : @"0"
  497. }.mutableCopy;
  498. FWWeakify(self)
  499. [[BogoNetwork shareInstance]GETV2:@"Weibo/release" param:parametersMDic success:^(BogoNetworkResponseModel * _Nonnull result) {
  500. [[BGHUDHelper sharedInstance]syncStopLoading];
  501. [_imageTimer invalidate];
  502. _imageTimer = nil;
  503. // NSInteger state = [NSString stringWithFormat:@"%@",result.status];
  504. // res
  505. // if(result.status.intValue == 1)
  506. // {
  507. //[[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"发布成功!")];
  508. [[BGHUDHelper sharedInstance] tipMessage:ASLocalizedString(@"发布成功!")];
  509. [[NSNotificationCenter defaultCenter] postNotificationName:@"changeTableViewStatus" object:nil];
  510. FWStrongify(self)
  511. // 执行退出
  512. @autoreleasepool {
  513. self.recordSuperViewC = nil;
  514. self.recordTabBarC = nil;
  515. self.videoMArray = nil;
  516. self.photoMArray = nil;
  517. self.tzImagePickerController = nil;
  518. // self.ossManager = nil;
  519. self.videoDynamicView = nil;
  520. self.navigationController.hidesBottomBarWhenPushed = NO;
  521. [self.navigationController popToRootViewControllerAnimated:YES];
  522. Noti_Post_Param(@"DynamicCommitSuccess", nil);
  523. }
  524. // }
  525. } failure:^(NSString * _Nonnull error) {
  526. [[BGHUDHelper sharedInstance]syncStopLoading];
  527. [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"发布失败!")];
  528. }];
  529. return;
  530. [[NetHttpsManager manager]POSTWithParameters:parametersMDic
  531. SuccessBlock:^(NSDictionary *responseJson) {
  532. [[BGHUDHelper sharedInstance]syncStopLoading];
  533. [_imageTimer invalidate];
  534. _imageTimer = nil;
  535. if( [[responseJson allKeys] containsObject:@"status"]&&[responseJson[@"status"] intValue] == 1)
  536. {
  537. //[[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"发布成功!")];
  538. [BGHUDHelper alert:ASLocalizedString(@"发布成功!")action:^{
  539. FWStrongify(self)
  540. // 执行退出
  541. @autoreleasepool {
  542. self.recordSuperViewC = nil;
  543. self.recordTabBarC = nil;
  544. self.videoMArray = nil;
  545. self.photoMArray = nil;
  546. self.tzImagePickerController = nil;
  547. // self.ossManager = nil;
  548. self.videoDynamicView = nil;
  549. self.navigationController.hidesBottomBarWhenPushed = NO;
  550. [self.navigationController popToRootViewControllerAnimated:YES];
  551. Noti_Post_Param(@"DynamicCommitSuccess", nil);
  552. }
  553. }];
  554. }
  555. } FailureBlock:^(NSError *error) {
  556. [[BGHUDHelper sharedInstance]syncStopLoading];
  557. [[BGHUDHelper sharedInstance]tipMessage:ASLocalizedString(@"发布失败!")];
  558. }];
  559. }
  560. #pragma -------------- <VideoDynamicViewDelegate>
  561. #pragma mark --去选择视频
  562. //父类已实现
  563. #pragma mark --发布
  564. - (void)submitData{
  565. [self showPublishDynamic];
  566. }
  567. #pragma mark --去封面编辑页面
  568. -(void)showOnVideoDynamicView:(VideoDynamicView *)videoDynamicView
  569. STTableShowVideoCell:(STTableShowVideoCell *)stTableShowVideoCell
  570. andChangeVideoCoverClick:(UIButton *)changeVideoCoverClick{
  571. //
  572. if (self.videoDynamicView.dataSoureMArray.count == 0)
  573. {
  574. return;
  575. }
  576. VideoCoverViewC *videoCoverViewC = (VideoCoverViewC *)[VideoCoverViewC showSTBaseViewCOnSuperViewC:self
  577. andFrameRect:CGRectMake(0, 0, kScreenW, kScreenH)
  578. andSTViewCTransitionType:STViewCTransitionTypeOfPush
  579. andComplete:^(BOOL finished,
  580. STBaseViewC *stBaseViewC) {
  581. }];
  582. videoCoverViewC.title = ASLocalizedString(@"编辑视频封面");
  583. // 数组
  584. [videoCoverViewC videoCoverView];
  585. videoCoverViewC.videoCoverView.collectionView.backgroundColor = [UIColor clearColor];
  586. videoCoverViewC.videoCoverView.collectionView.frame = CGRectMake(0,kScreenH-250, kScreenW, 150);
  587. //videoCoverViewC.videoCoverView.collectionView.backgroundColor = [UIColor redColor];
  588. //STVideoCoverLayout *layout = [STVideoCoverLayout new];
  589. UICollectionViewFlowLayout *layout = [UICollectionViewFlowLayout new];
  590. layout.itemSize = CGSizeMake(100, 100);
  591. layout.minimumLineSpacing = 2;
  592. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  593. videoCoverViewC.videoCoverView.collectionView.collectionViewLayout = layout;
  594. videoCoverViewC.videoCoverView.dataSourceMArray = self.videoDynamicView.dataSoureMArray;
  595. //设置首帧图
  596. [videoCoverViewC.videoCoverView.showSelectedImgView setImage:self.videoDynamicView.dataSoureMArray[0]];
  597. [videoCoverViewC.videoCoverView.collectionView reloadData];
  598. videoCoverViewC.navigationController.navigationBar.tintColor = kAppGrayColor1;
  599. [self.navigationController pushViewController:videoCoverViewC animated:YES];
  600. __weak typeof(self)weak_Self = self;
  601. videoCoverViewC.selectImgInMarrayblock = ^(NSInteger selectMArrayIndex){
  602. weak_Self.videoDynamicView.recordSelectIndex = selectMArrayIndex;
  603. [stTableShowVideoCell.bgImgView setImage:[UIImage boxblurImage:weak_Self.videoDynamicView.dataSoureMArray[selectMArrayIndex] withBlurNumber:1]];
  604. [stTableShowVideoCell.videoCoverImgView setImage:weak_Self.videoDynamicView.dataSoureMArray[selectMArrayIndex]];
  605. [stTableShowVideoCell.bgImgView setNeedsDisplay];
  606. [stTableShowVideoCell.videoCoverImgView setNeedsDisplay];
  607. };
  608. }
  609. - (void)goVCOnVideoDynamicView:(VideoDynamicView *)videoDynamicView STTableShowVideoCell:(STVideoCateCell *)cell andChooseCateClick:(QMUIButton *)btn{
  610. __weak __typeof(self)weakSelf = self;
  611. FDActionSheet *ac = [[FDActionSheet alloc]initWithTitle:ASLocalizedString(@"选择分类") message:nil];
  612. for (DTTopicModel *model in self.cateArray) {
  613. [ac addAction:[FDAction actionWithTitle:model.name type:FDActionTypeDefault CallBack:^{
  614. weakSelf.selectedTopicID = model.id;
  615. [btn setTitle:[NSString stringWithFormat:@"%@",model.name] forState:UIControlStateNormal];
  616. CGSize btnSize = [self preferredSizeWithMaxWidth:kScreenW-130 view:btn];
  617. btn.frame = CGRectMake(kScreenW-btnSize.width-30, 12, btnSize.width, 30);
  618. }]];
  619. }
  620. [ac addAction:[FDAction actionWithTitle:ASLocalizedString(@"取消") type:FDActionTypeCancel CallBack:nil]];
  621. [ac show:self.view];
  622. //进入分类页面
  623. // VideoCateVC *tmpController = [[VideoCateVC alloc]init];
  624. // tmpController.view.backgroundColor = kWhiteColor;
  625. // __weak __typeof(self)weakSelf = self;;
  626. // tmpController.releaseTopicBlock = ^(DTTopicModel * _Nonnull topic) {
  627. // btn.hidden = NO;
  628. // weakSelf.selectedTopicID = topic.id;
  629. // [btn setTitle:[NSString stringWithFormat:@"%@",topic.name] forState:UIControlStateNormal];
  630. // CGSize btnSize = [self preferredSizeWithMaxWidth:kScreenW-130 view:btn];
  631. //
  632. // btn.frame = CGRectMake(kScreenW-btnSize.width-50, 12, btnSize.width, 30);
  633. // };
  634. // [self.navigationController pushViewController:tmpController animated:YES];
  635. //选择分类后,设置frame
  636. }
  637. -(void)dynamicView:(VideoDynamicView *)dynamicView didSelectGood:(STTableLeftRightCell *)cell{
  638. BogoVideoShopAddViewController *addVC = [[BogoVideoShopAddViewController alloc]init];
  639. addVC.isVideoSelect = YES;
  640. [addVC setSelectVideoGoodCallBack:^(BogoCommodityDetailModel * _Nonnull model) {
  641. // cell.rightLab.backgroundColor = kBlueColor;
  642. self.shopModel = model;
  643. // cell.backgroundColor = UIColor.redColor;
  644. // [cell.leftBtn setTitle:@"31312" forState:UIControlStateNormal];
  645. // cell.rightLab.text = model.shop_title;
  646. cell.rightLabel.text = model.shop_title;
  647. // if (!StrValid(model.shop_title)) {
  648. // model.shop_title = model.title;
  649. // }
  650. NSLog(@"%@",cell);
  651. NSLog(@"%@",cell.rightLab);
  652. NSLog(@"%@",cell.leftBtn);
  653. }];
  654. [self.navigationController pushViewController:addVC animated:YES];
  655. }
  656. - (CGSize)preferredSizeWithMaxWidth:(CGFloat)maxWidth view:(QMUIButton *)btn
  657. {
  658. CGSize size = [btn sizeThatFits:CGSizeMake(maxWidth, 30)] ;
  659. return CGSizeMake(size.width +15, size.height);
  660. }
  661. #pragma mark mov格式转mp4格式
  662. - (void)movFileTransformToMP4WithSourceUrl:(NSURL *)sourceUrl completion:(void(^)(NSURL *Mp4FilePath))comepleteBlock
  663. {
  664. AVURLAsset *avAsset = [AVURLAsset URLAssetWithURL:sourceUrl options:nil];
  665. NSArray *compatiblePresets = [AVAssetExportSession exportPresetsCompatibleWithAsset:avAsset];
  666. if ([compatiblePresets containsObject:AVAssetExportPresetHighestQuality])
  667. {
  668. AVAssetExportSession *exportSession = [[AVAssetExportSession alloc] initWithAsset:avAsset presetName:AVAssetExportPresetHighestQuality];
  669. NSDateFormatter *formater = [[NSDateFormatter alloc] init];//用时间给文件全名,以免重复
  670. [formater setDateFormat:@"yyyy-MM-dd-HH:mm:ss"];
  671. NSString * resultPath = [NSHomeDirectory() stringByAppendingFormat:@"/Documents/output-%@.mp4", [formater stringFromDate:[NSDate date]]];
  672. exportSession.outputURL = [NSURL fileURLWithPath:resultPath];
  673. exportSession.outputFileType = AVFileTypeMPEG4;
  674. exportSession.shouldOptimizeForNetworkUse = YES;
  675. [exportSession exportAsynchronouslyWithCompletionHandler:^(void)
  676. {
  677. switch (exportSession.status) {
  678. case AVAssetExportSessionStatusUnknown:
  679. NSLog(@"AVAssetExportSessionStatusUnknown");
  680. break;
  681. case AVAssetExportSessionStatusWaiting:
  682. NSLog(@"AVAssetExportSessionStatusWaiting");
  683. break;
  684. case AVAssetExportSessionStatusExporting:
  685. NSLog(@"AVAssetExportSessionStatusExporting");
  686. break;
  687. case AVAssetExportSessionStatusCompleted:
  688. comepleteBlock(exportSession.outputURL);
  689. break;
  690. case AVAssetExportSessionStatusFailed:
  691. NSLog(@"AVAssetExportSessionStatusFailed");
  692. break;
  693. }
  694. }];
  695. }
  696. }
  697. - (NSMutableArray *)cateArray{
  698. if (!_cateArray) {
  699. _cateArray = [NSMutableArray array];
  700. }
  701. return _cateArray;
  702. }
  703. @end