Skip to content

Commit 128ab72

Browse files
author
ccharlesren
committed
接入滑动时间轴滚动条播放视频功能
Tapd: Tapd: http://tapd.oa.com/NEW_IOT/prong/stories/view/1020393192865698219 Change-Id: Iee6521f59570d184a99e35d1b510fd7355bc0edf
1 parent bfc0c99 commit 128ab72

File tree

2 files changed

+81
-56
lines changed

2 files changed

+81
-56
lines changed

Source/LinkSDKDemo/Video/P2P/View/CustomTimeSlider/TIoTDemoCustomChoiceDateView.m

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
288288
}
289289

290290
- (void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView {
291-
[self getTimeDataScorllEnd:scrollView];
291+
// [self getTimeDataScorllEnd:scrollView];
292292
}
293293

294294
- (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate {

Source/LinkSDKDemo/Video/PlayBack/LocalPlayBack/Controller/TIoTDemoLocalRecordVC.m

Lines changed: 80 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#import "TIoTCoreXP2PBridge.h"
2929
#import "NSString+Extension.h"
3030
#import "TIoTDemoLocalDayTimeListModel.h"
31+
#import "TIoTDemoDeviceStatusModel.h"
32+
#import "TIoTCoreUtil+TIoTDemoDeviceStatus.h"
3133

3234
static CGFloat const kPadding = 16;
3335
static NSString *const kPlaybackCustomCellID = @"kPlaybackCustomCellID";
@@ -145,8 +147,15 @@ -(void)viewWillDisappear:(BOOL)animated{
145147
- (void)viewDidDisappear:(BOOL)animated {
146148
[super viewDidDisappear:animated];
147149

148-
[self.player shutdown];
149-
[self removeMovieNotificationObservers];
150+
// [self.player shutdown];
151+
// [self removeMovieNotificationObservers];
152+
153+
[self.imageView.subviews enumerateObjectsUsingBlock:^(__kindof UIView * _Nonnull obj, NSUInteger idx, BOOL * _Nonnull stop) {
154+
UIView *view = obj;
155+
[view removeFromSuperview];
156+
}];
157+
158+
[self stopPlayMovie];
150159

151160
[self closeTime];
152161
}
@@ -269,8 +278,8 @@ - (void)setupUIViews {
269278
weakSelf.isInnerScroll = NO;
270279
weakSelf.isHidePlayBtn = YES;
271280
weakSelf.isPause = NO;
272-
[weakSelf playVideoWithPartURL:weakSelf.listModel.VideoURL withTime:previousModel isChangeModel:YES];
273-
281+
// [weakSelf playVideoWithStartTime:weakSelf.listModel.VideoURL withTime:previousModel isChangeModel:YES];
282+
[weakSelf seekDesignatedPointWithCurrentTime:previousModel.StartTime selectedTimeMoel:previousModel isChangeModel:YES];
274283
[weakSelf setScrollOffsetWith:previousModel];
275284
}
276285

@@ -294,8 +303,8 @@ - (void)setupUIViews {
294303
weakSelf.isInnerScroll = NO;
295304
weakSelf.isHidePlayBtn = YES;
296305
weakSelf.isPause = NO;
297-
[weakSelf playVideoWithPartURL:weakSelf.listModel.VideoURL withTime:nextModel isChangeModel:YES];
298-
306+
// [weakSelf playVideoWithStartTime:weakSelf.listModel.VideoURL withTime:nextModel isChangeModel:YES];
307+
[weakSelf seekDesignatedPointWithCurrentTime:nextModel.StartTime selectedTimeMoel:nextModel isChangeModel:YES];
299308
[weakSelf setScrollOffsetWith:nextModel];
300309
}
301310
};
@@ -333,10 +342,12 @@ - (void)setupUIViews {
333342
weakSelf.isHidePlayBtn = YES;
334343
weakSelf.isPause = NO;
335344

345+
NSString *videoPlayStart = [NSString stringWithFormat:@"%f",startTimestamp];
346+
336347
if (weakSelf.videoTimeModel.StartTime.integerValue <= startTimestamp && weakSelf.videoTimeModel.EndTime.integerValue >=startTimestamp ) {
337348

338349
if (weakSelf.player == nil) { //滑动到空数据,销毁player,重新请求
339-
[weakSelf playVideoWithPartURL:weakSelf.listModel.VideoURL withTime:currentModel isChangeModel:YES];
350+
[weakSelf seekDesignatedPointWithCurrentTime:videoPlayStart selectedTimeMoel:currentModel isChangeModel:YES];
340351
}else {
341352
if (weakSelf.isTimerSuspend == YES) {
342353
if (weakSelf.timer) {
@@ -359,7 +370,7 @@ - (void)setupUIViews {
359370
}
360371

361372
}else {
362-
[weakSelf playVideoWithPartURL:weakSelf.listModel.VideoURL withTime:currentModel isChangeModel:YES];
373+
[weakSelf seekDesignatedPointWithCurrentTime:videoPlayStart selectedTimeMoel:currentModel isChangeModel:YES];
363374
}
364375

365376
TIoTDemoCloudEventModel *scorllCurrentModel = [[TIoTDemoCloudEventModel alloc]init];
@@ -412,27 +423,19 @@ - (void)requestLocalRecordListDate {
412423
NSString *startTimeTemp = [NSString getTimeStampWithString:[NSString stringWithFormat:@"%@ 00:00:00",self.currentDayTime?:@""] withFormatter:@"YYYY-MM-dd HH:mm:ss" withTimezone:@""];
413424
NSString *endTimeTemp = [NSString getTimeStampWithString:[NSString stringWithFormat:@"%@ 23:59:59",self.currentDayTime?:@""] withFormatter:@"YYYY-MM-dd HH:mm:ss" withTimezone:@""];
414425

415-
NSString *actionString = [self getActioinStringWithStartTime:startTimeTemp endTime:endTimeTemp];
416-
417-
[self getLocalDayTimeListDataWithCmd:actionString];
418-
}
419-
420-
//MARK: 获取
421-
- (NSString *)getActioinStringWithStartTime:(NSString *)startTime endTime:(NSString *)endTime {
422-
NSString *action = @"";
423426
NSString *channel = @"0";
424427
if (self.isNVR == YES) {
425428
channel = self.deviceModel.Channel?:@"";
426429
}else {
427430
channel = @"0";
428431
}
429432

430-
action = [NSString stringWithFormat:@"action=inner_define&channel=%@&cmd=get_record_index&start_time=%@&end_time=%@",channel,startTime,endTime];
433+
NSString *actionString = [NSString stringWithFormat:@"action=inner_define&channel=%@&cmd=get_record_index&start_time=%@&end_time=%@",channel,startTimeTemp,endTimeTemp];
431434

432-
return action;
435+
[self getLocalDayTimeListDataWithCmd:actionString];
433436
}
434437

435-
///MARK:获取数据
438+
///MARK:查询时间后,获取数据
436439
- (void)getLocalDayTimeListDataWithCmd:(NSString *)actionString {
437440
[[TIoTCoreXP2PBridge sharedInstance] getCommandRequestWithAsync:self.deviceName?:@"" cmd:actionString timeout:2*1000*1000 completion:^(NSString * _Nonnull jsonList) {
438441
TIoTDemoLocalDayTimeListModel *data = [TIoTDemoLocalDayTimeListModel yy_modelWithJSON:jsonList];
@@ -467,7 +470,13 @@ - (void)getLocalDayTimeListDataWithCmd:(NSString *)actionString {
467470
self.isInnerScroll = NO;
468471
self.isPause = NO;
469472
// [self getFullVideoURLWithPartURL:data.VideoURL?:@"" withTime:model isChangeModel:YES];
470-
[self setVieoPlayerStartPlayWithDataList:data];
473+
474+
//此处 changeModel 为yes 需要单独指定
475+
self.videoTimeModel = [[TIoTDemoCloudEventModel alloc]init];
476+
self.videoTimeModel.StartTime = model.StartTime;
477+
self.videoTimeModel.EndTime = model.EndTime;
478+
479+
[self setVieoPlayerStartPlay];
471480
}
472481
}
473482

@@ -476,14 +485,51 @@ - (void)getLocalDayTimeListDataWithCmd:(NSString *)actionString {
476485
}];
477486
}
478487

488+
/// MARK: seek 进度条滚动
489+
- (void)seekDesignatedPointWithCurrentTime:(NSString *)currentTime selectedTimeMoel:(TIoTDemoCloudEventModel *)timeModel isChangeModel:(BOOL)isChange{
490+
491+
if (isChange == YES) {
492+
self.videoTimeModel = [[TIoTDemoCloudEventModel alloc]init];
493+
self.videoTimeModel.StartTime = timeModel.StartTime;
494+
self.videoTimeModel.EndTime = timeModel.EndTime;
495+
}
496+
497+
NSString *channel = @"0";
498+
if (self.isNVR == YES) {
499+
channel = self.deviceModel.Channel?:@"";
500+
}else {
501+
channel = @"0";
502+
}
503+
504+
[self stopPlayMovie];
505+
506+
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
507+
NSString *actionString = [NSString stringWithFormat:@"action=inner_define&channel=%@&cmd=playback_seek&time=%@",channel,currentTime];
508+
509+
[[TIoTCoreXP2PBridge sharedInstance] getCommandRequestWithAsync:self.deviceName?:@"" cmd:actionString timeout:2*1000*1000 completion:^(NSString * _Nonnull jsonList) {
510+
511+
TIoTDemoDeviceStatusModel *responseModel = [TIoTDemoDeviceStatusModel yy_modelWithJSON:jsonList];
512+
if ([responseModel.status isEqualToString:@"0"]) {
513+
//seek 指定时间后,设备状态正常,可起播放器
514+
[self setVieoPlayerStartPlay];
515+
516+
}else {
517+
//设备状态异常提示
518+
[TIoTCoreUtil showDeviceStatusError:responseModel commandInfo:[NSString stringWithFormat:@"发送信令: %@\n\n接收: %@",actionString,jsonList]];
519+
}
520+
}];
521+
});
522+
}
523+
479524
/// MARK:开启设备
480-
- (void)setVieoPlayerStartPlayWithDataList:(TIoTDemoLocalDayTimeListModel *)data {
525+
- (void)setVieoPlayerStartPlay {
526+
481527
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
482528

483529
NSString *channalID = @"";
530+
484531
if (self.isNVR == YES) {
485532
channalID = [NSString stringWithFormat:@"%@&channel=%@",kLive,self.deviceModel.Channel?:@""];
486-
487533
}else {
488534
channalID = [NSString stringWithFormat:@"%@&channel=0",kLive];
489535
}
@@ -492,16 +538,10 @@ - (void)setVieoPlayerStartPlayWithDataList:(TIoTDemoLocalDayTimeListModel *)data
492538

493539
self.videoUrl = [NSString stringWithFormat:@"%@%@",urlString,channalID?:@""];
494540

495-
// if (self.isHidePlayBtn == YES) {
496-
// [self stopPlayMovie];
497-
// [self configVideo];
498-
// [self.player prepareToPlay];
499-
// [self.player play];
500-
// [self autoHideControlView];
501-
// }
502541
[self configVideo];
503542
[self.player prepareToPlay];
504543
[self.player play];
544+
[self autoHideControlView];
505545

506546
/// 播放器出图开始时间
507547
// self.startPlayer = CACurrentMediaTime();
@@ -567,29 +607,6 @@ - (NSString *)getDeytimeFormat:(NSInteger)timestamp {
567607
return dateString;
568608
}
569609

570-
///MARK: 本地回放播放
571-
- (void)playVideoWithPartURL:(NSString *)videoPartURL withTime:(TIoTDemoCloudEventModel *)timeModel isChangeModel:(BOOL)isChange {
572-
if (isChange == YES) {
573-
self.videoTimeModel = [[TIoTDemoCloudEventModel alloc]init];
574-
self.videoTimeModel.StartTime = timeModel.StartTime;
575-
self.videoTimeModel.EndTime = timeModel.EndTime;
576-
}
577-
578-
//视频播放
579-
self.videoUrl = videoPartURL?:@"";
580-
if (self.isHidePlayBtn == YES) {
581-
[self stopPlayMovie];
582-
[self configVideo];
583-
[self.player prepareToPlay];
584-
[self.player play];
585-
[self autoHideControlView];
586-
}
587-
588-
[self configVideo];
589-
[self.player prepareToPlay];
590-
[self.player play];
591-
}
592-
593610
///MARK: 获取视频防盗链播放URL
594611
//- (void)getFullVideoURLWithPartURL:(NSString *)videoPartURL withTime:(TIoTDemoCloudEventModel *)timeModel isChangeModel:(BOOL)isChange
595612
//{
@@ -711,7 +728,8 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
711728
self.isInnerScroll = NO;
712729
self.isPause = NO;
713730
TIoTDemoCloudEventModel *selectedModel = self.dataArray[indexPath.row];
714-
[self playVideoWithPartURL:self.listModel.VideoURL withTime:selectedModel isChangeModel:YES];
731+
// [self playVideoWithStartTime:self.listModel.VideoURL withTime:selectedModel isChangeModel:YES];
732+
[self seekDesignatedPointWithCurrentTime:selectedModel.StartTime selectedTimeMoel:selectedModel isChangeModel:YES];
715733
[self setScrollOffsetWith:selectedModel];
716734
}
717735

@@ -1092,7 +1110,9 @@ - (void)sliderValueChanged:(id)sender {
10921110
self.isPause = NO;
10931111
self.player.currentPlaybackTime = self.currentTime;
10941112
[self startPlayVideoWithStartTime:self.videoTimeModel.StartTime.integerValue endTime:self.videoTimeModel.EndTime.integerValue sliderValue:self.player.currentPlaybackTime];
1113+
10951114
// [self getFullVideoURLWithPartURL:self.listModel.VideoURL withTime:currentTimeModel isChangeModel:NO];
1115+
[self seekDesignatedPointWithCurrentTime:currentTimeModel.StartTime selectedTimeMoel:currentTimeModel isChangeModel:NO];
10961116
[self setScrollOffsetWith:currentTimeModel];
10971117

10981118
}
@@ -1507,8 +1527,13 @@ - (void)configVideo {
15071527
}
15081528

15091529
- (void)stopPlayMovie {
1510-
[self.player stop];
1511-
self.player = nil;
1530+
1531+
if (self.player != nil) {
1532+
[self.player stop];
1533+
[self.player shutdown];
1534+
[self.player.view removeFromSuperview];
1535+
self.player = nil;
1536+
}
15121537
}
15131538

15141539
#pragma mark - lazy loading

0 commit comments

Comments
 (0)