Skip to content

Commit ec26b61

Browse files
committed
修复云存时间计算
Change-Id: I3280c0c030fe1c4be9be5a16fd9ad95ba6dce870
1 parent 8cefb98 commit ec26b61

File tree

5 files changed

+47
-26
lines changed

5 files changed

+47
-26
lines changed

Source/LinkSDKDemo/Video/P2P/Mjpeg/TIoTDemoPreviewMJPEGVC.m

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ - (void)clickTalkback:(UIButton *)button {
655655
- (void)clickPlayback:(UIButton *)button {
656656

657657
TIoTDemoPlaybackVC *playBackVC = [[TIoTDemoPlaybackVC alloc]init];
658+
playBackVC.isMJPEG = YES;
658659
playBackVC.device_xp2p_info = self.device_xp2p_info;
659660
playBackVC.deviceModel = self.selectedModel;
660661
playBackVC.isNVR = self.isNVR;
@@ -1004,6 +1005,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
10041005
//跳转回看页面,并播放当前选中事件视频,滚动条滑动相应位置
10051006
TIoTDemoCloudEventModel *itemModel = self.dataArray[indexPath.row];
10061007
TIoTDemoPlaybackVC *playBackVC = [[TIoTDemoPlaybackVC alloc]init];
1008+
playBackVC.isMJPEG = YES;
10071009
playBackVC.device_xp2p_info = self.device_xp2p_info;
10081010
playBackVC.eventItemModel = itemModel;
10091011
playBackVC.deviceModel = self.selectedModel;

Source/LinkSDKDemo/Video/PlayBack/CloudStorage/Controller/TIoTCloudStorageVC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ typedef void(^TIoTDemoCloudPlayerReloadBlock)(void);
2121
@property (nonatomic, strong) TIoTDemoCloudEventModel *eventItemModel; // 选择具体某个事件model
2222
@property (nonatomic, copy) TIoTDemoCloudPlayerReloadBlock playerReloadBlock;
2323
@property (nonatomic, strong) NSString *device_xp2p_info;
24+
@property (nonatomic, assign) BOOL isMJPEG;
2425
- (void)clearMessage;
2526
@end
2627

Source/LinkSDKDemo/Video/PlayBack/CloudStorage/Controller/TIoTCloudStorageVC.m

Lines changed: 42 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -167,10 +167,10 @@ - (void)viewDidDisappear:(BOOL)animated {
167167
- (void)dealloc{
168168
[[NSNotificationCenter defaultCenter]removeObserver:self];
169169
[[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications];
170+
[self closeTime];
170171

171172
[self stopCloudPlayMovie];
172173

173-
[self closeTime];
174174
printf("debugdeinit---%s,%s,%d", __FILE__, __FUNCTION__, __LINE__);
175175
}
176176

@@ -375,7 +375,7 @@ - (void)setupUIViews {
375375
if (weakSelf.cloudPlayer.isPlaying == NO) {
376376
[weakSelf tapCloudVideoView:weakSelf.playPauseBtn];
377377
}
378-
[weakSelf startPlayVideoWithStartTime:currentModel.StartTime.integerValue endTime:currentModel.EndTime.integerValue sliderValue:weakSelf.currentTime];
378+
// [weakSelf startPlayVideoWithStartTime:currentModel.StartTime.integerValue endTime:currentModel.EndTime.integerValue sliderValue:weakSelf.currentTime];
379379
}
380380

381381
}else {
@@ -523,6 +523,8 @@ - (void)getFullVideoURLWithPartURL:(NSString *)videoPartURL withTime:(TIoTDemoCl
523523

524524
///MARK: 获取mjpeg两路音视频
525525
- (void)getMJPEGVideoURLWithPartURL:(NSString *)videoPartURL withTime:(TIoTDemoCloudEventModel *)timeModel isChangeModel:(BOOL)isChange {
526+
self.videoTimeModel = timeModel;
527+
526528
NSMutableDictionary *paramDic = [[NSMutableDictionary alloc]init];
527529
paramDic[@"ProductId"] = [TIoTCoreAppEnvironment shareEnvironment].cloudProductId?:@"";
528530
paramDic[@"Version"] = @"2021-11-25";
@@ -547,11 +549,13 @@ - (void)getMJPEGVideoURLWithPartURL:(NSString *)videoPartURL withTime:(TIoTDemoC
547549
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
548550
[self.cloudPlayer prepareToPlay];
549551
[self.cloudPlayer play];
552+
553+
[self startPlayVideoWithStartTime:self.videoTimeModel.StartTime.integerValue endTime:self.videoTimeModel.EndTime.integerValue sliderValue:0];
554+
self.slider.maximumValue = self.videoTimeModel.EndTime.integerValue - self.videoTimeModel.StartTime.integerValue;
550555
});
551556

552557
[self.cloudAudioPlayer prepareToPlay];
553558
[self.cloudAudioPlayer play];
554-
555559

556560
self.videoPlayBtn.hidden = YES;
557561
self.customControlVidwoView.hidden = NO;
@@ -641,7 +645,7 @@ - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(N
641645

642646
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
643647
TIoTDemoCloudEventModel *selectedModel = self.dataArray[indexPath.row];
644-
if ([self.device_xp2p_info containsString:@"m"]) {
648+
if (self.isMJPEG) {
645649
NSLog(@"是mjpeg设备");
646650

647651
//下载下来播放-----start
@@ -898,6 +902,8 @@ - (void)playVideo:(UIButton *)button {
898902
[self configVideo];
899903
[self.cloudPlayer prepareToPlay];
900904
[self.cloudPlayer play];
905+
[self.cloudAudioPlayer prepareToPlay];
906+
[self.cloudAudioPlayer play];
901907
[self autoHideControlView];
902908

903909
self.cloudIsHidePlayBtn = YES;
@@ -907,6 +913,8 @@ - (void)playVideo:(UIButton *)button {
907913
[self configVideo];
908914
[self.cloudPlayer prepareToPlay];
909915
[self.cloudPlayer play];
916+
[self.cloudAudioPlayer prepareToPlay];
917+
[self.cloudAudioPlayer play];
910918
[self autoHideControlView];
911919
}
912920
[MBProgressHUD showLodingNoneEnabledInView:self.view withMessage:@""];
@@ -1273,7 +1281,6 @@ - (void)cloudMoviePlayBackStateDidChange:(NSNotification*)notification
12731281
DDLogInfo(@"IJKMPMoviePlayBackStateDidChange %d: playing", (int)_cloudPlayer.playbackState);
12741282
if (self.cloudIsPause == NO) {
12751283
}
1276-
// [self startPlayVideoWithStartTime:self.videoTimeModel.StartTime.integerValue endTime:self.videoTimeModel.EndTime.integerValue sliderValue:self.currentTime];
12771284
[MBProgressHUD dismissInView:self.view];
12781285
break;
12791286
}
@@ -1300,7 +1307,7 @@ - (void)cloudMoviePlayBackStateDidChange:(NSNotification*)notification
13001307

13011308
//计时器
13021309
- (void)startPlayVideoWithStartTime:(NSInteger )startTime endTime:(NSInteger )endTime sliderValue:(NSInteger)sliderValue{
1303-
return;
1310+
// return;
13041311
if (self.cloudTimer) {
13051312
if (self.cloudIsTimerSuspend == YES) {
13061313
dispatch_resume(self.cloudTimer);
@@ -1314,48 +1321,52 @@ - (void)startPlayVideoWithStartTime:(NSInteger )startTime endTime:(NSInteger )en
13141321
}
13151322
//播放时长 时间戳差值
13161323

1317-
__weak typeof(self) weakSelf = self;
1324+
// __weak typeof(self) weakSelf = self;
13181325

13191326
__block NSInteger time = sliderValue; //计时开始
13201327

13211328
NSInteger durationValue = self.cloudPlayer.duration;
1329+
if (durationValue < 1) {
1330+
durationValue = endTime - startTime;
1331+
}
13221332
NSInteger minuteValue = durationValue / 60;
13231333
NSInteger secondValue = durationValue % 60;
13241334

13251335
self.slider.minimumValue = 0;
13261336
self.slider.maximumValue = durationValue;
13271337

13281338
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
1329-
weakSelf.cloudTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
1339+
self.cloudTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
13301340

1331-
dispatch_source_set_timer(weakSelf.cloudTimer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
1341+
dispatch_source_set_timer(self.cloudTimer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
13321342

1333-
dispatch_source_set_event_handler(weakSelf.cloudTimer, ^{
1343+
dispatch_source_set_event_handler(self.cloudTimer, ^{
13341344

13351345
if(time >= durationValue){ //计时结束,关闭
13361346

1337-
dispatch_source_cancel(weakSelf.cloudTimer);
1347+
dispatch_source_cancel(self.cloudTimer);
13381348
dispatch_async(dispatch_get_main_queue(), ^{
1339-
[weakSelf stopCloudPlayMovie];
1349+
// [weakSelf stopCloudPlayMovie];
13401350
//起始时间等于duration
1341-
weakSelf.totalLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",minuteValue,secondValue];
1342-
weakSelf.currentLabel.text = weakSelf.totalLabel.text;
1343-
DDLogDebug(@"over:-----sliderValue:%f---currentTime:%f----totalTime:%f----playduratio:%f",self.slider.value,self.cloudPlayer.currentPlaybackTime,self.cloudPlayer.duration,self.cloudPlayer.playableDuration);
1351+
self.totalLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",minuteValue,secondValue];
1352+
self.currentLabel.text = self.totalLabel.text;
1353+
NSLog(@"over:-----sliderValue:%f---currentTime:%f----totalTime:%f----playduratio:%f",self.slider.value,self.cloudPlayer.currentPlaybackTime,self.cloudPlayer.duration,self.cloudPlayer.playableDuration);
13441354
});
13451355

13461356
}else{
13471357

13481358
dispatch_async(dispatch_get_main_queue(), ^{
1349-
weakSelf.currentLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",time/60,time%60];
1350-
weakSelf.totalLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",minuteValue,secondValue];;
1351-
weakSelf.slider.value = time;
1352-
DDLogDebug(@"duration:-----sliderValue:%f---currentTime:%f----totalTime:%f----playduratio:%f",self.slider.value,self.cloudPlayer.currentPlaybackTime,self.cloudPlayer.duration,self.cloudPlayer.playableDuration);
1359+
self.slider.maximumValue = durationValue;
1360+
self.currentLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",time/60,time%60];
1361+
self.totalLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",minuteValue,secondValue];;
1362+
self.slider.value = (float)time;
1363+
NSLog(@"duration:-----sliderValue:%f---slidermax:%f---currentTime:%f----totalTime:%ld----playduratio:%f",self.slider.value,self.slider.maximumValue,self.cloudPlayer.currentPlaybackTime,(long)time,self.cloudPlayer.playableDuration);
13531364
});
13541365
time++;
13551366

13561367
}
13571368
});
1358-
dispatch_resume(weakSelf.cloudTimer);
1369+
dispatch_resume(self.cloudTimer);
13591370
}
13601371

13611372
- (void)cloudMoviePlayBackDidFinish:(NSNotification*)notification
@@ -1448,7 +1459,7 @@ - (void)configVideo {
14481459
// [self.player setOptionIntValue:10 * 1000 forKey:@"analyzeduration" ofCategory:kIJKFFOptionCategoryFormat];
14491460

14501461

1451-
if ([self.device_xp2p_info containsString:@"m"]) {
1462+
if (self.isMJPEG) {
14521463
NSLog(@"是mjpeg设备");
14531464
self.cloudAudioPlayer = [[IJKFFMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:self.audioUrl] withOptions:options];
14541465
self.cloudAudioPlayer.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
@@ -1463,11 +1474,16 @@ - (void)configVideo {
14631474
}
14641475

14651476
- (void)stopCloudPlayMovie {
1466-
[self.cloudPlayer stop];
1467-
self.cloudPlayer = nil;
1468-
1469-
[self.cloudAudioPlayer stop];
1470-
self.cloudAudioPlayer = nil;
1477+
if (self.cloudPlayer != nil) {
1478+
[self.cloudPlayer stop];
1479+
[self.cloudPlayer.view removeFromSuperview];
1480+
self.cloudPlayer = nil;
1481+
}
1482+
if (self.cloudAudioPlayer != nil) {
1483+
[self.cloudAudioPlayer stop];
1484+
[self.cloudAudioPlayer.view removeFromSuperview];
1485+
self.cloudAudioPlayer = nil;
1486+
}
14711487
}
14721488

14731489
#pragma mark - lazy loading

Source/LinkSDKDemo/Video/PlayBack/TIoTDemoPlaybackVC.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ typedef void(^TIoTDemoPlayerReloadBlock)(void);
2222
@property (nonatomic, copy) NSString *deviceName;
2323
@property (nonatomic, assign) BOOL isFromHome;
2424
@property (nonatomic, strong) NSString *device_xp2p_info;
25+
@property (nonatomic, assign) BOOL isMJPEG;
2526
@end
2627

2728
NS_ASSUME_NONNULL_END

Source/LinkSDKDemo/Video/PlayBack/TIoTDemoPlaybackVC.m

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ - (NSArray *)childControllers {
169169
if (!_childControllers) {
170170

171171
self.cloudStorageVC = [[TIoTCloudStorageVC alloc]init];
172+
self.cloudStorageVC.isMJPEG = self.isMJPEG;
172173
self.localRecordVC = [[TIoTDemoLocalRecordVC alloc]init];
173174

174175
self.cloudStorageVC.title = @"云记录";

0 commit comments

Comments
 (0)