TCVideoTextViewController.m 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567
  1. //
  2. // TCVideoTextViewController.m
  3. // DeviceManageIOSApp
  4. //
  5. // Created by rushanting on 2017/5/18.
  6. // Copyright © 2017年 tencent. All rights reserved.
  7. //
  8. #import "TCVideoTextViewController.h"
  9. #import "TXVideoEditer.h"
  10. #import "TCVideoPreview.h"
  11. #import "UIView+Additions.h"
  12. #import "ColorMacro.h"
  13. #import "TCRangeContent.h"
  14. #import "TCTextCollectionCell.h"
  15. #import "TCVideoTextFiled.h"
  16. @implementation TCVideoTextInfo
  17. @end
  18. @interface TCVideoTextViewController () <TCVideoPreviewDelegate, UICollectionViewDelegate, UICollectionViewDataSource, TCRangeContentDelegate, TCVideoTextFieldDelegate>
  19. {
  20. TCVideoPreview *_videoPreview;
  21. TXVideoEditer* _ugcEditer;
  22. TCRangeContent* _videoRangeSlider;
  23. UISlider* _progressView;
  24. UILabel* _progressedLabel;
  25. UICollectionView* _videoTextCollection;
  26. UIButton* _playBtn;
  27. CGFloat _videoStartTime;
  28. UILabel* _leftTimeLabel;
  29. CGFloat _videoEndTime;
  30. UILabel* _rightTimeLabel;
  31. CGFloat _videoDuration;
  32. UILabel* _timeLabel;
  33. BOOL _isVideoPlaying;
  34. NSMutableArray<TCVideoTextInfo*>* _videoTextInfos;
  35. }
  36. @end
  37. @implementation TCVideoTextViewController
  38. - (id)initWithVideoEditer:(TXVideoEditer *)videoEditer previewView:(TCVideoPreview *)previewView startTime:(CGFloat)startTime endTime:(CGFloat)endTime videoTextInfos:(NSArray<TCVideoTextInfo *> *)videoTextInfos
  39. {
  40. if (self = [super init]) {
  41. _ugcEditer = videoEditer;
  42. _videoPreview = previewView;
  43. _videoPreview.delegate = self;
  44. _videoStartTime = startTime;
  45. _videoEndTime = endTime;
  46. _videoDuration = endTime - startTime;
  47. _videoTextInfos = videoTextInfos.mutableCopy;
  48. if (!_videoTextInfos) {
  49. _videoTextInfos = [NSMutableArray new];
  50. } else {
  51. for (TCVideoTextInfo* textInfo in _videoTextInfos) {
  52. textInfo.textField.delegate = self;
  53. }
  54. }
  55. }
  56. return self;
  57. }
  58. - (void)viewDidLoad {
  59. [super viewDidLoad];
  60. // Do any additional setup after loading the view.
  61. [self initUI];
  62. }
  63. - (void)viewWillAppear:(BOOL)animated
  64. {
  65. [super viewWillAppear:animated];
  66. self.navigationController.navigationBar.barTintColor = UIColorFromRGB(0x181818);
  67. self.navigationController.navigationBar.translucent = NO;
  68. [UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
  69. }
  70. - (void)viewDidAppear:(BOOL)animated
  71. {
  72. [super viewDidAppear:animated];
  73. }
  74. - (void)dealloc
  75. {
  76. NSLog(@"VideoTextViewController dealloc");
  77. }
  78. - (void)initUI
  79. {
  80. UILabel *barTitleLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 0 , 100, 44)];
  81. barTitleLabel.backgroundColor = [UIColor clearColor];
  82. barTitleLabel.font = [UIFont boldSystemFontOfSize:17];
  83. barTitleLabel.textColor = [UIColor whiteColor];
  84. barTitleLabel.textAlignment = NSTextAlignmentCenter;
  85. barTitleLabel.text = NSLocalizedString(@"TCVideoCutView.VideoEdit", nil);
  86. self.navigationItem.titleView = barTitleLabel;;
  87. UIBarButtonItem *customBackButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(@"Common.Back", nil)
  88. style:UIBarButtonItemStylePlain
  89. target:self
  90. action:@selector(goBack)];
  91. customBackButton.tintColor = UIColorFromRGB(0x0accac);
  92. self.navigationItem.leftBarButtonItem = customBackButton;
  93. self.view.backgroundColor = UIColor.blackColor;
  94. _videoPreview.frame = CGRectMake(0, 0, self.view.width, 432 * kScaleY);
  95. _videoPreview.delegate = self;
  96. _videoPreview.backgroundColor = UIColor.darkTextColor;
  97. [_ugcEditer previewAtTime:_videoStartTime];
  98. [_ugcEditer pausePlay];
  99. _isVideoPlaying = NO;
  100. [_videoPreview setPlayBtnHidden:YES];
  101. [self.view addSubview:_videoPreview];
  102. UIImage* image = [UIImage imageNamed:@"videotext_play"];
  103. _playBtn = [[UIButton alloc] initWithFrame:CGRectMake(15 * kScaleX, _videoPreview.bottom + 30 * kScaleY, image.size.width, image.size.height)];
  104. [_playBtn setImage:image forState:UIControlStateNormal];
  105. [_playBtn addTarget:self action:@selector(onPlayBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
  106. [self.view addSubview:_playBtn];
  107. _timeLabel = [[UILabel alloc] init];
  108. _timeLabel.text = [NSString stringWithFormat:@"%02d:%02d", (int)(_videoDuration) / 60, (int)(_videoDuration) % 60];
  109. _timeLabel.textColor = UIColorFromRGB(0x777777);
  110. _timeLabel.font = [UIFont systemFontOfSize:14];
  111. [_timeLabel sizeToFit];
  112. _timeLabel.center = CGPointMake(self.view.width - 15 * kScaleX - _timeLabel.width / 2, _playBtn.center.y);
  113. [self.view addSubview:_timeLabel];
  114. UIView* toImageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.width, 2)];
  115. toImageView.backgroundColor = UIColor.lightGrayColor;
  116. UIImage* coverImage = toImageView.toImage;
  117. toImageView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 18, 18)];
  118. toImageView.backgroundColor = UIColorFromRGB(0x0accac);
  119. toImageView.layer.cornerRadius = 9;
  120. UIImage* thumbImage = toImageView.toImage;
  121. TCRangeContentConfig* config = [[TCRangeContentConfig alloc] init];
  122. config.pinWidth = 18;
  123. config.borderHeight = 0;
  124. config.thumbHeight = 20;
  125. config.leftPinImage = thumbImage;
  126. config.rightPigImage = thumbImage;
  127. config.leftCorverImage = coverImage;
  128. config.rightCoverImage = coverImage;
  129. toImageView = [UIView new];
  130. toImageView.backgroundColor = UIColorFromRGB(0x0accac);
  131. toImageView.bounds = CGRectMake(0, 0, _timeLabel.left - _playBtn.right - 15 - config.pinWidth * 2, 2);
  132. _videoRangeSlider = [[TCRangeContent alloc] initWithImageList:@[toImageView.toImage] config:config];
  133. _videoRangeSlider.center = CGPointMake(_playBtn.right + 7.5 + _videoRangeSlider.width / 2, _playBtn.center.y);
  134. _videoRangeSlider.delegate = self;
  135. _videoRangeSlider.hidden = YES;
  136. [self.view addSubview:_videoRangeSlider];
  137. _leftTimeLabel = [[UILabel alloc] init];
  138. _leftTimeLabel.textColor = UIColorFromRGB(0x777777);
  139. _leftTimeLabel.font = [UIFont systemFontOfSize:10];
  140. _leftTimeLabel.text = @"0:00";
  141. _leftTimeLabel.hidden = YES;
  142. [self.view addSubview:_leftTimeLabel];
  143. _rightTimeLabel = [[UILabel alloc] init];
  144. _rightTimeLabel.textColor = UIColorFromRGB(0x777777);
  145. _rightTimeLabel.font = [UIFont systemFontOfSize:10];
  146. _rightTimeLabel.text = @"0:00";
  147. _rightTimeLabel.hidden = YES;
  148. [self.view addSubview:_rightTimeLabel];
  149. _progressView = [UISlider new];
  150. _progressView.center = _videoRangeSlider.center;
  151. _progressView.bounds = CGRectMake(0, 0, _videoRangeSlider.width, 20);
  152. [self.view addSubview:_progressView];
  153. _progressView.tintColor = UIColorFromRGB(0x0accac);
  154. [_progressView setThumbImage:thumbImage forState:UIControlStateNormal];
  155. _progressView.minimumValue = _videoStartTime;
  156. _progressView.maximumValue = _videoEndTime;
  157. [_progressView addTarget:self action:@selector(onProgressSlided:) forControlEvents:UIControlEventValueChanged];
  158. [_progressView addTarget:self action:@selector(onProgressSlideEnd:) forControlEvents:UIControlEventTouchUpInside];
  159. _progressedLabel = [[UILabel alloc] initWithFrame:CGRectMake(_progressView.x, _progressView.y - 12, 30, 10)];
  160. _progressedLabel.textColor = UIColorFromRGB(0x777777);
  161. _progressedLabel.text = @"0:00";
  162. _progressedLabel.font = [UIFont systemFontOfSize:10];
  163. [self.view addSubview:_progressedLabel];
  164. UIView* bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.height - (40 + 40 * kScaleY) - 65, self.view.width, (40 + 40 * kScaleY))];
  165. bottomView.backgroundColor = UIColorFromRGB(0x181818);
  166. [self.view addSubview:bottomView];
  167. UIButton* newTextBtn = [[UIButton alloc] initWithFrame:CGRectMake(17.5 * kScaleX, 20 * kScaleY, 40, 40)];
  168. [newTextBtn setImage:[UIImage imageNamed:@"text_add"] forState:UIControlStateNormal];
  169. newTextBtn.backgroundColor = UIColor.clearColor;
  170. newTextBtn.layer.borderWidth = 1;
  171. newTextBtn.layer.borderColor = UIColorFromRGB(0x777777).CGColor;
  172. [newTextBtn addTarget:self action:@selector(onNewTextBtnClicked:) forControlEvents:UIControlEventTouchUpInside];
  173. [bottomView addSubview:newTextBtn];
  174. UICollectionViewFlowLayout* layout = [UICollectionViewFlowLayout new];
  175. layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;
  176. _videoTextCollection = [[UICollectionView alloc] initWithFrame:CGRectMake(newTextBtn.right + 10, 20 * kScaleY, self.view.width - 35 - 10, 40) collectionViewLayout:layout];
  177. _videoTextCollection.delegate = self;
  178. _videoTextCollection.dataSource = self;
  179. _videoTextCollection.backgroundColor = UIColor.clearColor;
  180. _videoTextCollection.allowsMultipleSelection = NO;
  181. [_videoTextCollection registerClass:[TCTextCollectionCell class] forCellWithReuseIdentifier:@"TCTextCollectionCell"];
  182. [bottomView addSubview:_videoTextCollection];
  183. }
  184. - (void)setProgressHidden:(BOOL)isHidden
  185. {
  186. [_playBtn setImage:[UIImage imageNamed:@"videotext_play"] forState:UIControlStateNormal];
  187. if (isHidden) {
  188. _progressView.hidden = YES;
  189. _progressedLabel.hidden = YES;
  190. _videoRangeSlider.hidden = NO;
  191. _leftTimeLabel.hidden = NO;
  192. _rightTimeLabel.hidden = NO;
  193. [_ugcEditer pausePlay];
  194. _isVideoPlaying = NO;
  195. [_ugcEditer previewAtTime:_videoRangeSlider.leftScale * (_videoDuration) + _videoStartTime];
  196. } else {
  197. _progressView.hidden = NO;
  198. _progressedLabel.hidden = NO;
  199. _videoRangeSlider.hidden = YES;
  200. _leftTimeLabel.hidden = YES;
  201. _rightTimeLabel.hidden = YES;
  202. NSArray* indexPaths = [_videoTextCollection indexPathsForSelectedItems];
  203. if (indexPaths.count > 0) {
  204. [_videoTextCollection deselectItemAtIndexPath:indexPaths[0] animated:NO];
  205. }
  206. [self showVideoTextInfo:nil];
  207. }
  208. }
  209. - (TCVideoTextInfo*)getSelectedVideoTextInfo
  210. {
  211. NSIndexPath* selectedIndexPath = [_videoTextCollection indexPathsForSelectedItems][0];
  212. if (selectedIndexPath.row < _videoTextInfos.count) {
  213. return _videoTextInfos[selectedIndexPath.row];
  214. }
  215. return nil;
  216. }
  217. - (void)showVideoTextInfo:(TCVideoTextInfo*)textInfo
  218. {
  219. NSMutableArray<TCVideoTextInfo*>* videoTexts = [NSMutableArray new];
  220. for (TCVideoTextInfo* info in _videoTextInfos) {
  221. info.textField.hidden = YES;
  222. if (info != textInfo) {
  223. [videoTexts addObject:info];
  224. }
  225. }
  226. if (!textInfo)
  227. return;
  228. textInfo.textField.hidden = NO;
  229. [_videoPreview addSubview:textInfo.textField];
  230. CGFloat leftX = MAX(0, (textInfo.startTime - _videoStartTime)) / (_videoDuration) * _videoRangeSlider.imageWidth;
  231. CGFloat rightX = MIN(_videoDuration, (textInfo.endTime - _videoStartTime)) / (_videoDuration) * _videoRangeSlider.imageWidth;
  232. _videoRangeSlider.leftPinCenterX = leftX + _videoRangeSlider.pinWidth / 2;
  233. _videoRangeSlider.rightPinCenterX = MAX(_videoRangeSlider.leftPinCenterX + _videoRangeSlider.pinWidth, rightX + _videoRangeSlider.pinWidth * 3 / 2);
  234. [_videoRangeSlider setNeedsLayout];
  235. _leftTimeLabel.frame = CGRectMake(_videoRangeSlider.x + _videoRangeSlider.leftPinCenterX - _videoRangeSlider.pinWidth / 2, _videoRangeSlider.top - 12, 30, 10);
  236. _leftTimeLabel.text = [NSString stringWithFormat:@"%.02f", _videoRangeSlider.leftScale *_videoDuration];
  237. _rightTimeLabel.frame = CGRectMake(_videoRangeSlider.x + _videoRangeSlider.rightPinCenterX - _videoRangeSlider.pinWidth / 2, _videoRangeSlider.top - 12, 30, 10);
  238. _rightTimeLabel.text = [NSString stringWithFormat:@"%.02f", _videoRangeSlider.rightScale *_videoDuration];
  239. [self setVideoSubtitles:videoTexts];
  240. [self setProgressHidden:YES];
  241. }
  242. - (void)setVideoSubtitles:(NSArray<TCVideoTextInfo*>*)videoTextInfos
  243. {
  244. NSMutableArray* subtitles = [NSMutableArray new];
  245. //UIImageView* imageView = [UIImageView new];
  246. //imageView.contentMode = UIViewContentModeCenter;
  247. //[_videoPreview addSubview:imageView];
  248. //imageView.backgroundColor = UIColor.redColor;
  249. NSMutableArray<TCVideoTextInfo*>* emptyVideoTexts;
  250. for (TCVideoTextInfo* textInfo in videoTextInfos) {
  251. if (textInfo.textField.text.length < 1) {
  252. [emptyVideoTexts addObject:textInfo];
  253. continue;
  254. }
  255. TXSubtitle* subtitle = [TXSubtitle new];
  256. subtitle.titleImage = textInfo.textField.textImage;
  257. subtitle.frame = [textInfo.textField textFrameOnView:_videoPreview];
  258. subtitle.startTime = textInfo.startTime;
  259. subtitle.endTime = textInfo.endTime;
  260. //imageView.frame = CGRectMake(subtitle.frame.origin.x, subtitle.frame.origin.y, subtitle.frame.size.width, subtitle.frame.size.height);
  261. //imageView.image = subtitle.titleImage;
  262. [subtitles addObject:subtitle];
  263. }
  264. [_ugcEditer setSubtitleList:subtitles];
  265. }
  266. #pragma mark - UICollectionViewDataSource
  267. - (NSInteger)numberOfSectionsInCollectionView:(UICollectionView *)collectionView
  268. {
  269. return 1;
  270. }
  271. - (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section
  272. {
  273. return _videoTextInfos.count;
  274. }
  275. - (UICollectionViewCell*)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
  276. {
  277. static NSString *identify = @"TCTextCollectionCell";
  278. TCTextCollectionCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:identify forIndexPath:indexPath];
  279. if (indexPath.row < _videoTextInfos.count) {
  280. TCVideoTextInfo* info = _videoTextInfos[indexPath.row];
  281. cell.textLabel.text = info.textField.text;
  282. }
  283. return cell;
  284. }
  285. - (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath
  286. {
  287. TCVideoTextInfo* textInfo = [self getSelectedVideoTextInfo];
  288. [self showVideoTextInfo:textInfo];
  289. }
  290. - (CGSize)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout sizeForItemAtIndexPath:(NSIndexPath *)indexPath
  291. {
  292. return CGSizeMake(40, 40);
  293. }
  294. //设置每个item水平间距
  295. - (CGFloat)collectionView:(UICollectionView *)collectionView layout:(UICollectionViewLayout *)collectionViewLayout minimumInteritemSpacingForSectionAtIndex:(NSInteger)section
  296. {
  297. return 10;
  298. }
  299. #pragma mark - UI event Handle
  300. - (void)onPlayBtnClicked:(UIButton*)sender
  301. {
  302. [self setProgressHidden:NO];
  303. if (!_isVideoPlaying) {
  304. [self setVideoSubtitles:_videoTextInfos];
  305. [_ugcEditer startPlayFromTime:_videoStartTime toTime:_videoEndTime];
  306. [_playBtn setImage:[UIImage imageNamed:@"videotext_stop"] forState:UIControlStateNormal];
  307. _isVideoPlaying = YES;
  308. } else {
  309. [_ugcEditer pausePlay];
  310. [_playBtn setImage:[UIImage imageNamed:@"videotext_play"] forState:UIControlStateNormal];
  311. _isVideoPlaying = NO;
  312. }
  313. }
  314. - (void)onNewTextBtnClicked:(UIButton*)sender
  315. {
  316. [self setProgressHidden:YES];
  317. TCVideoTextFiled* videoTextField = [[TCVideoTextFiled alloc] initWithFrame:CGRectMake((_videoPreview.width - 170) / 2, (_videoPreview.height - 50) / 2, 170, 50)];
  318. videoTextField.delegate = self;
  319. [_videoPreview addSubview:videoTextField];
  320. CGFloat segDuration = (_videoDuration - 0.1) / 10;
  321. int segIndex = _videoTextInfos.count % 10;
  322. TCVideoTextInfo* info = [TCVideoTextInfo new];
  323. info.textField = videoTextField;
  324. info.startTime = _videoStartTime + segDuration * segIndex;
  325. info.endTime = info.startTime + segDuration;
  326. [_videoTextInfos addObject:info];
  327. [_videoTextCollection reloadData];
  328. [_videoTextCollection performBatchUpdates:nil completion:^(BOOL finished) {
  329. NSIndexPath* indexPath = [NSIndexPath indexPathForRow:_videoTextInfos.count - 1 inSection:0];
  330. [_videoTextCollection selectItemAtIndexPath:indexPath animated:YES scrollPosition:UICollectionViewScrollPositionCenteredHorizontally];
  331. }];
  332. [self showVideoTextInfo:info];
  333. }
  334. - (void)onProgressSlided:(UISlider*)progressSlider
  335. {
  336. _progressedLabel.x = _progressView.x + (progressSlider.value - _videoStartTime) / _videoDuration * (_progressView.width - _progressView.currentThumbImage.size.width);
  337. _progressedLabel.text = [NSString stringWithFormat:@"%.02f", progressSlider.value - _videoStartTime];
  338. [_ugcEditer previewAtTime:progressSlider.value];
  339. }
  340. - (void)onProgressSlideEnd:(UISlider*)progressSlider
  341. {
  342. // [_ugcEditer pausePlay];
  343. [_ugcEditer startPlayFromTime:progressSlider.value toTime:_videoEndTime];
  344. _isVideoPlaying = YES;
  345. [_playBtn setImage:[UIImage imageNamed:@"videotext_stop"] forState:UIControlStateNormal];
  346. }
  347. - (void)goBack
  348. {
  349. [self setVideoSubtitles:_videoTextInfos];
  350. for (TCVideoTextInfo* info in _videoTextInfos) {
  351. [info.textField resignFirstResponser];
  352. [info.textField removeFromSuperview];
  353. }
  354. [_videoPreview removeFromSuperview];
  355. [self.delegate onSetVideoTextInfosFinish:_videoTextInfos];
  356. [self dismissViewControllerAnimated:YES completion:nil];
  357. }
  358. #pragma mark - VideoTextFieldDelegate
  359. - (void)onTextInputDone:(NSString *)text
  360. {
  361. NSIndexPath* selectedIndexPath = [_videoTextCollection indexPathsForSelectedItems][0];
  362. TCTextCollectionCell* selectedCell = (TCTextCollectionCell*)[_videoTextCollection cellForItemAtIndexPath:selectedIndexPath];
  363. selectedCell.textLabel.text = text;
  364. }
  365. - (void)onRemoveTextField:(TCVideoTextFiled *)textField
  366. {
  367. TCVideoTextInfo* info = [self getSelectedVideoTextInfo];
  368. [info.textField resignFirstResponser];
  369. [_videoTextInfos removeObject:info];
  370. [_videoTextCollection reloadData];
  371. [self setProgressHidden:NO];
  372. [self setVideoSubtitles:_videoTextInfos];
  373. }
  374. #pragma mark - RangeContentDelegate
  375. - (void)onRangeLeftChanged:(TCRangeContent *)sender
  376. {
  377. CGFloat textStartTime = _videoStartTime + sender.leftScale * (_videoDuration);
  378. //[_ugcEditer startPlayFromTime:textStartTime toTime:textEndTime];
  379. [_ugcEditer previewAtTime:textStartTime];
  380. _leftTimeLabel.frame = CGRectMake(_videoRangeSlider.x + _videoRangeSlider.leftPin.x, _videoRangeSlider.top - 12, 30, 10);
  381. _leftTimeLabel.text = [NSString stringWithFormat:@"%.02f", sender.leftScale * _videoDuration];
  382. }
  383. - (void)onRangeLeftChangeEnded:(TCRangeContent *)sender
  384. {
  385. CGFloat textStartTime = _videoStartTime + sender.leftScale * (_videoDuration);
  386. //[_ugcEditer startPlayFromTime:textStartTime toTime:textEndTime];
  387. [_ugcEditer previewAtTime:textStartTime];
  388. TCVideoTextInfo* textInfo = [self getSelectedVideoTextInfo];
  389. textInfo.startTime = textStartTime;
  390. }
  391. - (void)onRangeRightChanged:(TCRangeContent *)sender
  392. {
  393. CGFloat textEndTime = _videoStartTime+ sender.rightScale * (_videoDuration);
  394. [_ugcEditer previewAtTime:textEndTime];
  395. _rightTimeLabel.frame = CGRectMake(_videoRangeSlider.x + _videoRangeSlider.rightPin.x, _videoRangeSlider.top - 12, 30, 10);
  396. _rightTimeLabel.text = [NSString stringWithFormat:@"%.02f", sender.rightScale * _videoDuration];
  397. }
  398. - (void)onRangeRightChangeEnded:(TCRangeContent *)sender
  399. {
  400. CGFloat textEndTime = _videoStartTime+ sender.rightScale * (_videoDuration);
  401. [_ugcEditer previewAtTime:textEndTime];
  402. TCVideoTextInfo* textInfo = [self getSelectedVideoTextInfo];
  403. textInfo.endTime = textEndTime;
  404. }
  405. #pragma mark - VideoPreviewDelegate
  406. - (void)onVideoPlay
  407. {
  408. [_ugcEditer startPlayFromTime:_videoStartTime toTime:_videoEndTime];
  409. [_playBtn setImage:[UIImage imageNamed:@"videotext_stop"] forState:UIControlStateNormal];
  410. _isVideoPlaying = YES;
  411. }
  412. - (void)onVideoPause
  413. {
  414. [_ugcEditer pausePlay];
  415. [_playBtn setImage:[UIImage imageNamed:@"videotext_play"] forState:UIControlStateNormal];
  416. _isVideoPlaying = NO;
  417. }
  418. - (void)onVideoResume
  419. {
  420. //[_ugcEditer resumePlay];
  421. [_ugcEditer startPlayFromTime:_progressView.value toTime:_videoEndTime];
  422. _isVideoPlaying = YES;
  423. }
  424. - (void)onVideoPlayProgress:(CGFloat)time
  425. {
  426. _progressView.value = time;
  427. _progressedLabel.text = [NSString stringWithFormat:@"%.02f", time - _videoStartTime];
  428. _progressedLabel.x = _progressView.x + (time - _videoStartTime) / _videoDuration * (_progressView.width - _progressView.currentThumbImage.size.width);
  429. }
  430. - (void)onVideoPlayFinished
  431. {
  432. _isVideoPlaying = NO;
  433. [self onVideoPlay];
  434. }
  435. - (void)onVideoEnterBackground
  436. {
  437. if (_isVideoPlaying) {
  438. [_ugcEditer pausePlay];
  439. [_playBtn setImage:[UIImage imageNamed:@"videotext_play"] forState:UIControlStateNormal];
  440. _isVideoPlaying = NO;
  441. }
  442. }
  443. @end