TCVideoPublishController.m 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706
  1. #import "TCVideoPublishController.h"
  2. #import "UIView+CustomAutoLayout.h"
  3. #import <UShareUI/UMSocialUIManager.h>
  4. #import "NSString+Common.h"
  5. #import "TCUserInfoModel.h"
  6. #import "TXUGCPublish.h"
  7. //#import "TCLoginModel.h"
  8. #import <AFNetworking.h>
  9. //#import "TCLoginParam.h"
  10. @interface TCVideoPublishController()
  11. @property UILabel *labPublishState;
  12. @property BOOL isNetWorkErr;
  13. @property UIImageView *imgPublishState;
  14. @end
  15. @implementation TCVideoPublishController
  16. {
  17. //分享
  18. UIView *_vShare;
  19. UIView *_vShareInfo;
  20. UIView *_vVideoPreview;
  21. UITextView *_txtShareWords;
  22. UILabel *_labDefaultWords;
  23. UILabel *_labLeftWords;
  24. UILabel *_labRecordVideo;
  25. UIView *_vSharePlatform;
  26. NSMutableArray *_btnShareArry;
  27. //发布
  28. UIView *_vPublishInfo;
  29. UIImageView *_imgPublishState;
  30. UILabel *_labPublishState;
  31. TXUGCPublish *_videoPublish;
  32. TXLivePlayer *_livePlayer;
  33. TXPublishParam *_videoPublishParams;
  34. TXRecordResult *_recordResult;
  35. NSInteger _selectBtnTag;
  36. BOOL _isPublished;
  37. BOOL _playEnable;
  38. id _videoRecorder;
  39. BOOL _isNetWorkErr;
  40. }
  41. - (instancetype)init:(id)videoRecorder recordType:(NSInteger)recordType RecordResult:(TXRecordResult *)recordResult TCLiveInfo:(TCLiveInfo *)liveInfo
  42. {
  43. self = [super init];
  44. if (self) {
  45. _videoPublishParams = [[TXPublishParam alloc] init];
  46. _recordResult = recordResult;
  47. _videoRecorder = videoRecorder;
  48. _isPublished = NO;
  49. _playEnable = YES;
  50. _isNetWorkErr = NO;
  51. _selectBtnTag = -1;
  52. _videoPublish = [[TXUGCPublish alloc] initWithUserID:[[TCUserInfoModel sharedInstance] getUserProfile].identifier];
  53. _videoPublish.delegate = self;
  54. _livePlayer = [[TXLivePlayer alloc] init];
  55. _livePlayer.delegate = self;
  56. [[NSNotificationCenter defaultCenter] addObserver:self
  57. selector:@selector(applicationWillEnterForeground:)
  58. name:UIApplicationWillEnterForegroundNotification
  59. object:nil];
  60. [[NSNotificationCenter defaultCenter] addObserver:self
  61. selector:@selector(applicationDidEnterBackground:)
  62. name:UIApplicationDidEnterBackgroundNotification
  63. object:nil];
  64. }
  65. return self;
  66. }
  67. - (instancetype)initWithPath:(NSString *)videoPath videoMsg:(TXVideoInfo *) videoMsg
  68. {
  69. TXRecordResult *recordResult = [TXRecordResult new];
  70. recordResult.coverImage = videoMsg.coverImage;
  71. recordResult.videoPath = videoPath;
  72. return [self init:nil recordType:0
  73. RecordResult:recordResult
  74. TCLiveInfo:nil];
  75. }
  76. - (void)dealloc
  77. {
  78. [_livePlayer removeVideoWidget];
  79. [[NSNotificationCenter defaultCenter] removeObserver:self];
  80. [[AFNetworkReachabilityManager sharedManager] stopMonitoring];
  81. }
  82. - (void)viewDidLoad
  83. {
  84. [super viewDidLoad];
  85. self.navigationController.navigationBar.tintColor = UIColorFromRGB(0x0ACCAC);
  86. self.navigationItem.title = NSLocalizedString(@"Common.Release", nil);
  87. [self.navigationController.navigationBar setTitleTextAttributes:@{NSFontAttributeName:[UIFont systemFontOfSize:18],NSForegroundColorAttributeName:[UIColor blackColor]}] ;
  88. self.view.backgroundColor = UIColorFromRGB(0xefeff4);
  89. UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Common.Release", nil) style:UIBarButtonItemStylePlain target:self action:@selector(videoPublish)];
  90. self.navigationItem.rightBarButtonItems = [NSMutableArray arrayWithObject:btn];
  91. self.view.userInteractionEnabled = YES;
  92. UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyboard:)];
  93. singleTap.cancelsTouchesInView = NO;
  94. [self.view addGestureRecognizer:singleTap];
  95. //分享
  96. _vShare = [[UIView alloc] init];
  97. _vShare.backgroundColor = [UIColor clearColor];
  98. _vShareInfo = [[UIView alloc] init];
  99. _vShareInfo.backgroundColor = [UIColor whiteColor];
  100. _vVideoPreview = [[UIView alloc] init];
  101. _txtShareWords = [[UITextView alloc] init];
  102. _txtShareWords.delegate = self;
  103. _txtShareWords.layer.borderColor = _vShareInfo.backgroundColor.CGColor;
  104. _txtShareWords.font = [UIFont systemFontOfSize:16];
  105. _txtShareWords.textColor = UIColorFromRGB(0x0ACCAC);
  106. _labDefaultWords = [[UILabel alloc] init];
  107. _labDefaultWords.text = NSLocalizedString(@"TCVideoPublish.SaySomething", nil);
  108. _labDefaultWords.textColor = UIColorFromRGB(0xefeff4);
  109. _labDefaultWords.font = [UIFont systemFontOfSize:16];
  110. _labDefaultWords.backgroundColor =[UIColor clearColor];
  111. _labDefaultWords.textAlignment = NSTextAlignmentLeft;
  112. _labLeftWords = [[UILabel alloc] init];
  113. _labLeftWords.text = @"0/500";
  114. _labLeftWords.textColor = UIColorFromRGB(0xefeff4);
  115. _labLeftWords.font = [UIFont systemFontOfSize:12];
  116. _labLeftWords.backgroundColor =[UIColor clearColor];
  117. _labLeftWords.textAlignment = NSTextAlignmentRight;
  118. _vSharePlatform = [[UIView alloc] init];
  119. _vSharePlatform.backgroundColor = [UIColor whiteColor];
  120. NSArray * shareTitleArray = @[
  121. NSLocalizedString(@"ShareTitleArray1", nil),
  122. NSLocalizedString(@"ShareTitleArray2", nil),
  123. NSLocalizedString(@"ShareTitleArray3", nil),
  124. NSLocalizedString(@"ShareTitleArray4", nil),
  125. NSLocalizedString(@"ShareTitleArray5", nil)];
  126. NSArray * shareIconPressArray = @[
  127. @"video_record_wechat",
  128. @"video_record_friends",
  129. @"video_record_QQ",
  130. @"video_record_Qzone",
  131. @"video_record_sina"];
  132. NSArray * shareIconArray = @[
  133. @"video_record_wechat_gray",
  134. @"video_record_friends_gray",
  135. @"video_record_QQ_gray",
  136. @"video_record_Qzone_gray",
  137. @"video_record_sina_gray"];
  138. _btnShareArry = [[NSMutableArray alloc] init];
  139. for(int i=0; i<shareTitleArray.count && i<shareIconArray.count && i<shareIconPressArray.count; ++i)
  140. {
  141. UIButton * _btn = [UIButton buttonWithType:UIButtonTypeCustom];
  142. [_btn setImage:[UIImage imageNamed:[shareIconArray objectAtIndex:i]] forState:UIControlStateNormal];
  143. [_btn setImage:[UIImage imageNamed:[shareIconPressArray objectAtIndex:i]] forState:UIControlStateSelected];
  144. [_btn setTitle:[shareTitleArray objectAtIndex:i] forState:UIControlStateNormal];
  145. [_btn setTitleColor:UIColorFromRGB(0x777777) forState:UIControlStateNormal];
  146. _btn.titleLabel.font = [UIFont systemFontOfSize:12];
  147. [_btn addTarget:self action:@selector(selectShare:) forControlEvents:UIControlEventTouchUpInside];
  148. _btn.tag = i;
  149. _btn.selected = NO;
  150. // [_btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
  151. [_btnShareArry addObject:_btn];
  152. [_vSharePlatform addSubview:_btn];
  153. }
  154. [_vShare addSubview:_vSharePlatform];
  155. [self.view addSubview:_vShare];
  156. [_vShare addSubview:_vShareInfo];
  157. [_vShareInfo addSubview:_vVideoPreview];
  158. [_vShareInfo addSubview:_txtShareWords];
  159. [_vShareInfo addSubview:_labDefaultWords];
  160. [_vShareInfo addSubview:_labLeftWords];
  161. [_vShare sizeWith:CGSizeMake(self.view.width, self.view.height - [[UIApplication sharedApplication] statusBarFrame].size.height - self.navigationController.navigationBar.height)];
  162. [_vShare alignParentTopWithMargin:[[UIApplication sharedApplication] statusBarFrame].size.height+self.navigationController.navigationBar.height];
  163. [_vShare alignParentLeft];
  164. [_vShareInfo setSize:CGSizeMake(self.view.width, 180)];
  165. [self setBorderWithView:_vShareInfo top:YES left:NO bottom:YES right:NO borderColor:UIColorFromRGB(0xd8d8d8) borderWidth:0.5];
  166. [_vShareInfo alignParentTopWithMargin:42];
  167. [_vShareInfo alignParentLeft];
  168. [_vSharePlatform setSize:CGSizeMake(self.view.width, 100)];
  169. [self setBorderWithView:_vSharePlatform top:YES left:NO bottom:YES right:NO borderColor:UIColorFromRGB(0xd8d8d8) borderWidth:0.5];
  170. [_vSharePlatform alignParentTopWithMargin:264];
  171. [_vSharePlatform alignParentLeft];
  172. [_vVideoPreview setSize:CGSizeMake(100, 150)];
  173. [_vVideoPreview alignParentLeftWithMargin:15];
  174. [_vVideoPreview alignParentTopWithMargin:15];
  175. [_txtShareWords setSize:CGSizeMake(self.view.width - _vVideoPreview.width - 45, _vVideoPreview.height)];
  176. [_txtShareWords layoutToRightOf:_vVideoPreview margin:15];
  177. [_txtShareWords alignParentTopWithMargin:15];
  178. [_labDefaultWords setSize:CGSizeMake(90, 16)];
  179. [_labDefaultWords layoutToRightOf:_vVideoPreview margin:25];
  180. [_labDefaultWords alignParentTopWithMargin:24];
  181. [_labLeftWords setSize:CGSizeMake(50, 12)];
  182. [_labLeftWords alignParentRightWithMargin:15];
  183. [_labLeftWords alignParentBottomWithMargin:15];
  184. UILabel* publish_promise = [[UILabel alloc] init];
  185. publish_promise.text = NSLocalizedString(@"TCVideoPublish.ReleaseToApp", nil);
  186. publish_promise.textColor = UIColorFromRGB(0x777777);
  187. publish_promise.font = [UIFont systemFontOfSize:12];
  188. publish_promise.backgroundColor =[UIColor clearColor];
  189. publish_promise.textAlignment = NSTextAlignmentLeft;
  190. [_vShare addSubview:publish_promise];
  191. [publish_promise setSize:CGSizeMake(90, 12)];
  192. [publish_promise alignParentTopWithMargin:20];
  193. [publish_promise alignParentLeftWithMargin:15];
  194. UILabel* share_promise = [[UILabel alloc] init];
  195. share_promise.text = NSLocalizedString(@"TCVideoPublish.AndShareTo", nil);
  196. share_promise.textColor = UIColorFromRGB(0x777777);
  197. share_promise.font = [UIFont systemFontOfSize:12];
  198. share_promise.backgroundColor =[UIColor clearColor];
  199. share_promise.textAlignment = NSTextAlignmentLeft;
  200. [_vShare addSubview:share_promise];
  201. [share_promise setSize:CGSizeMake(90, 12)];
  202. [share_promise alignParentTopWithMargin:242];
  203. [share_promise alignParentLeftWithMargin:15];
  204. int gap = 15;
  205. int shareBtnWidth = 45;
  206. if (_btnShareArry.count > 1) gap = (self.view.width - 30 - _btnShareArry.count*shareBtnWidth)/(_btnShareArry.count-1);
  207. for(int i=0; i<_btnShareArry.count; ++i)
  208. {
  209. UIButton *btn = [_btnShareArry objectAtIndex:i];
  210. [btn setSize:CGSizeMake(shareBtnWidth, 70)];
  211. if (0 == i) {
  212. [btn alignParentLeftWithMargin:15];
  213. } else {
  214. [btn layoutToRightOf:[_btnShareArry objectAtIndex:i-1] margin:gap];
  215. }
  216. [btn alignParentTopWithMargin:15];
  217. btn.titleLabel.backgroundColor = btn.backgroundColor;
  218. btn.imageView.backgroundColor = btn.backgroundColor;
  219. CGSize titleSize = btn.titleLabel.bounds.size;
  220. CGSize imageSize = btn.imageView.bounds.size;
  221. CGFloat interval = 8.0;
  222. //(CGFloat top, CGFloat left, CGFloat bottom, CGFloat right)
  223. [btn setImageEdgeInsets:UIEdgeInsetsMake(0,0, titleSize.height + interval, -(titleSize.width))];
  224. [btn setTitleEdgeInsets:UIEdgeInsetsMake(imageSize.height + interval, -(imageSize.width), 0, 0)];
  225. }
  226. //发布
  227. _vPublishInfo = [[UIView alloc] init];
  228. _vPublishInfo.backgroundColor = [UIColor clearColor];
  229. _vPublishInfo.hidden = YES;
  230. _imgPublishState = [[UIImageView alloc] init];
  231. _imgPublishState.image = [UIImage imageNamed:@"video_record_share_loading_0"];
  232. _labPublishState = [[UILabel alloc] init];
  233. _labPublishState.text = NSLocalizedString(@"TCVideoPublish.VideoUploading", nil);
  234. _labPublishState.textColor = UIColorFromRGB(0x0ACCAC);
  235. _labPublishState.font = [UIFont systemFontOfSize:24];
  236. _labPublishState.backgroundColor =[UIColor clearColor];
  237. _labPublishState.textAlignment = NSTextAlignmentCenter;
  238. _labRecordVideo = [[UILabel alloc] init];
  239. _labRecordVideo.text = @"";
  240. _labRecordVideo.textColor = UIColorFromRGB(0x0ACCAC);
  241. _labRecordVideo.font = [UIFont systemFontOfSize:12];
  242. _labRecordVideo.backgroundColor =[UIColor clearColor];
  243. _labRecordVideo.numberOfLines = 0;
  244. _labRecordVideo.lineBreakMode = NSLineBreakByWordWrapping;
  245. _labRecordVideo.textAlignment = NSTextAlignmentCenter;
  246. [self.view addSubview:_vPublishInfo];
  247. [_vPublishInfo addSubview:_imgPublishState];
  248. [_vPublishInfo addSubview:_labPublishState];
  249. [_vPublishInfo addSubview:_labRecordVideo];
  250. [_vPublishInfo sizeWith:CGSizeMake(self.view.width, self.view.height - [[UIApplication sharedApplication] statusBarFrame].size.height - self.navigationController.navigationBar.height)];
  251. [_vPublishInfo alignParentTopWithMargin:[[UIApplication sharedApplication] statusBarFrame].size.height+self.navigationController.navigationBar.height];
  252. [_vPublishInfo alignParentLeft];
  253. [_imgPublishState setSize:CGSizeMake(50, 50)];
  254. [_imgPublishState alignParentTopWithMargin:100];
  255. _imgPublishState.center = CGPointMake(self.view.center.x, _imgPublishState.center.y);
  256. [_labPublishState setSize:CGSizeMake(self.view.width, 24)];
  257. [_labPublishState alignParentTopWithMargin:175];
  258. _labPublishState.center = CGPointMake(self.view.center.x, _labPublishState.center.y);
  259. _labRecordVideo.hidden = YES;
  260. [_livePlayer setupVideoWidget:CGRectZero containView:_vVideoPreview insertIndex:0];
  261. }
  262. - (void)setBorderWithView:(UIView *)view top:(BOOL)top left:(BOOL)left bottom:(BOOL)bottom right:(BOOL)right borderColor:(UIColor *)color borderWidth:(CGFloat)width
  263. {
  264. if (top) {
  265. CALayer *layer = [CALayer layer];
  266. layer.frame = CGRectMake(0, 0, view.frame.size.width, width);
  267. layer.backgroundColor = color.CGColor;
  268. [view.layer addSublayer:layer];
  269. }
  270. if (left) {
  271. CALayer *layer = [CALayer layer];
  272. layer.frame = CGRectMake(0, 0, width, view.frame.size.height);
  273. layer.backgroundColor = color.CGColor;
  274. [view.layer addSublayer:layer];
  275. }
  276. if (bottom) {
  277. CALayer *layer = [CALayer layer];
  278. layer.frame = CGRectMake(0, view.frame.size.height - width, view.frame.size.width, width);
  279. layer.backgroundColor = color.CGColor;
  280. [view.layer addSublayer:layer];
  281. }
  282. if (right) {
  283. CALayer *layer = [CALayer layer];
  284. layer.frame = CGRectMake(view.frame.size.width - width, 0, width, view.frame.size.height);
  285. layer.backgroundColor = color.CGColor;
  286. [view.layer addSublayer:layer];
  287. }
  288. }
  289. -(void)viewDidAppear:(BOOL)animated
  290. {
  291. [super viewDidAppear:animated];
  292. [self.navigationController setNavigationBarHidden:NO];
  293. _playEnable = YES;
  294. if (_isPublished == NO) {
  295. #warning 暂时注释
  296. // [_livePlayer startLivePlay:_recordResult.videoPath type:PLAY_TYPE_LOCAL_VIDEO];
  297. // [_livePlayer startPlay:_recordResult.videoPath type:PLAY_TYPE_LOCAL_VIDEO];
  298. }
  299. }
  300. - (void)viewDidDisappear:(BOOL)animated
  301. {
  302. [super viewDidDisappear:animated];
  303. [self.navigationController setNavigationBarHidden:NO];
  304. _playEnable = NO;
  305. [_livePlayer stopPlay];
  306. }
  307. - (void)closeKeyboard:(UITapGestureRecognizer *)gestureRecognizer
  308. {
  309. [_txtShareWords resignFirstResponder];
  310. }
  311. - (void)videoPublish
  312. {
  313. // [[TCLoginModel sharedInstance] getVodSign:^(int errCode, NSString *msg, NSDictionary *resultDict){
  314. // if (200 == errCode && resultDict[@"signature"]) {
  315. // _videoPublishParams.signature = resultDict[@"signature"];
  316. // _videoPublishParams.coverPath = [self getCoverPath:_recordResult.coverImage];
  317. // _videoPublishParams.videoPath = _recordResult.videoPath;
  318. // errCode = [_videoPublish publishVideo:_videoPublishParams];
  319. // }else{
  320. // [self toastTip:[NSString stringWithFormat:NSLocalizedString(@"TCVideoPublish.HintFetchingSignatureFailedFmt", nil), errCode]];
  321. // return;
  322. // }
  323. //
  324. // __weak typeof(self) wkSelf = self;
  325. // [[AFNetworkReachabilityManager sharedManager] setReachabilityStatusChangeBlock:^(AFNetworkReachabilityStatus status) {
  326. // switch (status) {
  327. // case AFNetworkReachabilityStatusNotReachable:
  328. // wkSelf.labPublishState.text = NSLocalizedString(@"TCVideoPublish.HintUploadingFailedNetwork", nil);
  329. // wkSelf.imgPublishState.hidden = YES;
  330. // wkSelf.isNetWorkErr = YES;
  331. // break;
  332. // default:
  333. // break;
  334. // }
  335. // }];
  336. // [[AFNetworkReachabilityManager sharedManager] startMonitoring]; //开启网络监控
  337. //
  338. // if(errCode != 0){
  339. // [self toastTip:[NSString stringWithFormat:NSLocalizedString(@"TCVideoPublish.HintUploadingFailedFmt", nil), errCode]];
  340. // return;
  341. // }
  342. //
  343. // self.navigationItem.rightBarButtonItems = nil;
  344. // self.navigationItem.title = NSLocalizedString(@"TCVideoPublish.PublishingTitle", nil);
  345. //
  346. // _vPublishInfo.hidden = NO;
  347. // _vShare.hidden = YES;
  348. //
  349. // _labPublishState.text = NSLocalizedString(@"TCVideoPublish.PublishingHint", nil);
  350. // _imgPublishState.image = [UIImage imageNamed:@"video_record_share_loading_0"];
  351. //
  352. // [_txtShareWords resignFirstResponder];
  353. // [_livePlayer stopPlay];
  354. // }];
  355. }
  356. #pragma mark - UITextViewDelegate
  357. - (void)textViewDidChange:(UITextView*)textView
  358. {
  359. if([textView.text length] == 0){
  360. _labDefaultWords.hidden = NO;
  361. }else{
  362. _labDefaultWords.hidden = YES;
  363. }
  364. _labLeftWords.text = [NSString stringWithFormat:@"%02ld/500", 500 - (long)[textView.text length]];
  365. }
  366. - (BOOL)textView:(UITextView*)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString*)text
  367. {
  368. if ([text isEqualToString:@"\n"]) {
  369. [textView resignFirstResponder];
  370. }
  371. if (range.location >= 500)
  372. {
  373. return NO;
  374. } else {
  375. return YES;
  376. }
  377. }
  378. #pragma mark - TXVideoPublishListener
  379. -(void) onPublishProgress:(uint64_t)uploadBytes totalBytes: (uint64_t)totalBytes
  380. {
  381. long progress = (long)(8 * uploadBytes / totalBytes);
  382. _imgPublishState.image = [UIImage imageNamed:[NSString stringWithFormat:@"video_record_share_loading_%ld", progress]];
  383. }
  384. -(void) onPublishComplete:(TXPublishResult*)result
  385. {
  386. if (!result.retCode) {
  387. _labPublishState.text = NSLocalizedString(@"TCVideoPublish.PublishingSucceeded", nil);
  388. } else {
  389. if (_isNetWorkErr == NO) {
  390. _labPublishState.text = [NSString stringWithFormat:NSLocalizedString(@"TCVideoPublish.PublishingFailedFmt", nil), result.retCode];
  391. }
  392. return;
  393. }
  394. // NSString *title = _txtShareWords.text;
  395. // if (title.length<=0) title = NSLocalizedString(@"Common.App", nil);
  396. // NSDictionary* dictParam = @{@"userid" :[TCLoginParam shareInstance].identifier,
  397. // @"file_id" : result.videoId,
  398. // @"title":title,
  399. // @"frontcover":result.coverURL == nil ? @"" : result.coverURL,
  400. // @"location":NSLocalizedString(@"Common.Unknown", nil),
  401. // @"play_url":result.videoURL};
  402. // [[TCLoginModel sharedInstance] uploadUGC:dictParam completion:^(int errCode, NSString *msg, NSDictionary *resultDict) {
  403. // if (200 == errCode) {
  404. // if (_selectBtnTag >= 0) {
  405. // int shareIndex[] = {1,2,4,5,0};
  406. // [self shareDataWithPlatform:shareIndex[_selectBtnTag] withFileID:result.videoId];
  407. // }
  408. // } else {
  409. // [self toastTip:[NSString stringWithFormat:@"UploadUGCVideo Failed[%d]", errCode]];
  410. // }
  411. //
  412. // _isPublished = YES;
  413. // }];
  414. //
  415. // _imgPublishState.image = [UIImage imageNamed:@"video_record_success"];
  416. // UIBarButtonItem *btn = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Common.Done", nil) style:UIBarButtonItemStylePlain target:self action:@selector(publishFinished)];
  417. // self.navigationItem.rightBarButtonItems = [NSMutableArray arrayWithObject:btn];
  418. }
  419. - (void)selectShare:(UIButton *)button
  420. {
  421. for(int i=0; i<_btnShareArry.count; ++i)
  422. {
  423. UIButton *btn = [_btnShareArry objectAtIndex:i];
  424. if (button == btn) {
  425. continue;
  426. }
  427. btn.selected = NO;
  428. }
  429. if (button.selected == YES) {
  430. button.selected = NO;
  431. _selectBtnTag = -1;
  432. } else {
  433. button.selected = YES;
  434. _selectBtnTag = button.tag;
  435. }
  436. }
  437. - (void)shareDataWithPlatform:(UMSocialPlatformType)platformType withFileID:(NSString *)fileId
  438. {
  439. TCUserInfoData *profile = [[TCUserInfoModel sharedInstance] getUserProfile];
  440. // 创建UMSocialMessageObject实例进行分享
  441. // 分享数据对象
  442. UMSocialMessageObject *messageObject = [UMSocialMessageObject messageObject];
  443. NSString *title = _txtShareWords.text;
  444. NSString *text = [NSString stringWithFormat:NSLocalizedString(@"TCVideoPublish.WhoseAppFmt", nil), profile.nickName ? profile.nickName: profile.identifier];
  445. if ( [title length] == 0) title = text;
  446. NSString *url = [NSString stringWithFormat:@"%@?userid=%@&type=%@&fileid=%@&ts=%@&sdkappid=%@&acctype=%@",
  447. kLivePlayShareAddr,
  448. TC_PROTECT_STR([profile.identifier stringByUrlEncoding]),
  449. [NSString stringWithFormat:@"%d", 2],
  450. TC_PROTECT_STR([fileId stringByUrlEncoding]),
  451. [NSString stringWithFormat:@"%d", 2],
  452. [[TCUserInfoModel sharedInstance] getUserProfile].appid,
  453. [[TCUserInfoModel sharedInstance] getUserProfile].accountType];
  454. /* 以下分享类型,开发者可根据需求调用 */
  455. // 1、纯文本分享
  456. messageObject.text = text;
  457. // 2、 图片或图文分享
  458. // 图片分享参数可设置URL、NSData类型
  459. // 注意:由于iOS系统限制(iOS9+),非HTTPS的URL图片可能会分享失败
  460. UMShareImageObject *shareObject = [UMShareImageObject shareObjectWithTitle:title descr:text thumImage:_recordResult.coverImage];
  461. [shareObject setShareImage:_recordResult.coverImage];
  462. UMShareWebpageObject *share2Object = [UMShareWebpageObject shareObjectWithTitle:title descr:text thumImage:_recordResult.coverImage];
  463. share2Object.webpageUrl = url;
  464. //新浪微博有个bug,放在shareObject里面设置url,分享到网页版的微博不显示URL链接,这里在text后面也加上链接
  465. if (platformType == UMSocialPlatformType_Sina) {
  466. messageObject.text = [NSString stringWithFormat:@"%@ %@",messageObject.text,share2Object.webpageUrl];
  467. }else{
  468. messageObject.shareObject = share2Object;
  469. }
  470. [[UMSocialManager defaultManager] shareToPlatform:platformType messageObject:messageObject currentViewController:self completion:^(id data, NSError *error) {
  471. NSString *message = nil;
  472. if (!error) {
  473. message = [NSString stringWithFormat:NSLocalizedString(@"TCBasePlayView.ShareSucceeded", nil)];
  474. } else {
  475. if (error.code == UMSocialPlatformErrorType_Cancel) {
  476. message = [NSString stringWithFormat:NSLocalizedString(@"TCBasePlayView.ShareCanceled", nil)];
  477. } else if (error.code == UMSocialPlatformErrorType_NotInstall) {
  478. message = [NSString stringWithFormat:NSLocalizedString(@"TCBasePlayView.AppNotInstalled", nil)];
  479. } else {
  480. message = [NSString stringWithFormat:NSLocalizedString(@"TCBasePlayView.ShareFailed", nil),(int)error.code];
  481. }
  482. }
  483. UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@""
  484. message:message
  485. delegate:nil
  486. cancelButtonTitle:NSLocalizedString(@"Common.OK", nil)
  487. otherButtonTitles:nil];
  488. [alert show];
  489. }];
  490. }
  491. - (void)applicationWillEnterForeground:(NSNotification *)noti
  492. {
  493. //temporary fix bug
  494. if ([self.navigationItem.title isEqualToString:NSLocalizedString(@"TCVideoPublish.PublishingTitle", nil)])
  495. return;
  496. if (_isPublished == NO) {
  497. #warning 暂时注释
  498. // [_livePlayer startLivePlay:_recordResult.videoPath type:PLAY_TYPE_LOCAL_VIDEO];
  499. }
  500. }
  501. - (void)publishFinished
  502. {
  503. if ([_videoRecorder isMemberOfClass:[TXLivePlayer class]]) {
  504. [self.navigationController popViewControllerAnimated:YES];
  505. } else {
  506. [self dismissViewControllerAnimated:YES completion:^{
  507. }];
  508. }
  509. }
  510. - (void)applicationDidEnterBackground:(NSNotification *)noti
  511. {
  512. [_livePlayer stopPlay];
  513. }
  514. #pragma mark TXLivePlayListener
  515. -(void) onPlayEvent:(int)EvtID withParam:(NSDictionary*)param
  516. {
  517. dispatch_async(dispatch_get_main_queue(), ^{
  518. if (EvtID == PLAY_EVT_PLAY_END && _playEnable) {
  519. [_livePlayer stopPlay];
  520. #warning 暂时注释
  521. // [_livePlayer startLivePlay:_recordResult.videoPath type:PLAY_TYPE_LOCAL_VIDEO];
  522. return;
  523. }
  524. });
  525. }
  526. -(void) onNetStatus:(NSDictionary*) param
  527. {
  528. return;
  529. }
  530. #pragma mark Utils
  531. - (float) heightForString:(UITextView *)textView andWidth:(float)width{
  532. CGSize sizeToFit = [textView sizeThatFits:CGSizeMake(width, MAXFLOAT)];
  533. return sizeToFit.height;
  534. }
  535. - (void) toastTip:(NSString*)toastInfo
  536. {
  537. CGRect frameRC = [[UIScreen mainScreen] bounds];
  538. frameRC.origin.y = frameRC.size.height - 110;
  539. frameRC.size.height -= 110;
  540. __block UITextView * toastView = [[UITextView alloc] init];
  541. toastView.editable = NO;
  542. toastView.selectable = NO;
  543. frameRC.size.height = [self heightForString:toastView andWidth:frameRC.size.width];
  544. toastView.frame = frameRC;
  545. toastView.text = toastInfo;
  546. toastView.backgroundColor = [UIColor whiteColor];
  547. toastView.alpha = 0.5;
  548. [self.view addSubview:toastView];
  549. dispatch_time_t popTime = dispatch_time(DISPATCH_TIME_NOW, 2 * NSEC_PER_SEC);
  550. dispatch_after(popTime, dispatch_get_main_queue(), ^(){
  551. [toastView removeFromSuperview];
  552. toastView = nil;
  553. });
  554. }
  555. -(NSString *)getCoverPath:(UIImage *)coverImage
  556. {
  557. UIImage *image = coverImage;
  558. if (image == nil) {
  559. return nil;
  560. }
  561. NSString *coverPath = [NSTemporaryDirectory() stringByAppendingPathComponent:@"TXUGC"];
  562. coverPath = [coverPath stringByAppendingPathComponent:[self getFileNameByTimeNow:@"TXUGC" fileType:@"jpg"]];
  563. if (coverPath) {
  564. // 保证目录存在
  565. [[NSFileManager defaultManager] createDirectoryAtPath:[coverPath stringByDeletingLastPathComponent]
  566. withIntermediateDirectories:YES
  567. attributes:nil
  568. error:nil];
  569. [UIImageJPEGRepresentation(image, 1.0) writeToFile:coverPath atomically:YES];
  570. }
  571. return coverPath;
  572. }
  573. -(NSString *)getFileNameByTimeNow:(NSString *)type fileType:(NSString *)fileType {
  574. NSTimeInterval now = [[NSDate date] timeIntervalSince1970];
  575. NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
  576. [formatter setDateFormat:@"yyyyMMdd_HHmmss"];
  577. NSDate * NowDate = [NSDate dateWithTimeIntervalSince1970:now];
  578. ;
  579. NSString * timeStr = [formatter stringFromDate:NowDate];
  580. NSString *fileName = ((fileType == nil) ||
  581. (fileType.length == 0)
  582. ) ? [NSString stringWithFormat:@"%@_%@",type,timeStr] : [NSString stringWithFormat:@"%@_%@.%@",type,timeStr,fileType];
  583. return fileName;
  584. }
  585. @end