Skip to content

Commit

Permalink
修复云存时间计算
Browse files Browse the repository at this point in the history
Change-Id: I3280c0c030fe1c4be9be5a16fd9ad95ba6dce870
  • Loading branch information
tonychanchen committed Sep 8, 2022
1 parent 8cefb98 commit ec26b61
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 26 deletions.
2 changes: 2 additions & 0 deletions Source/LinkSDKDemo/Video/P2P/Mjpeg/TIoTDemoPreviewMJPEGVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -655,6 +655,7 @@ - (void)clickTalkback:(UIButton *)button {
- (void)clickPlayback:(UIButton *)button {

TIoTDemoPlaybackVC *playBackVC = [[TIoTDemoPlaybackVC alloc]init];
playBackVC.isMJPEG = YES;
playBackVC.device_xp2p_info = self.device_xp2p_info;
playBackVC.deviceModel = self.selectedModel;
playBackVC.isNVR = self.isNVR;
Expand Down Expand Up @@ -1004,6 +1005,7 @@ - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath
//跳转回看页面,并播放当前选中事件视频,滚动条滑动相应位置
TIoTDemoCloudEventModel *itemModel = self.dataArray[indexPath.row];
TIoTDemoPlaybackVC *playBackVC = [[TIoTDemoPlaybackVC alloc]init];
playBackVC.isMJPEG = YES;
playBackVC.device_xp2p_info = self.device_xp2p_info;
playBackVC.eventItemModel = itemModel;
playBackVC.deviceModel = self.selectedModel;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ typedef void(^TIoTDemoCloudPlayerReloadBlock)(void);
@property (nonatomic, strong) TIoTDemoCloudEventModel *eventItemModel; // 选择具体某个事件model
@property (nonatomic, copy) TIoTDemoCloudPlayerReloadBlock playerReloadBlock;
@property (nonatomic, strong) NSString *device_xp2p_info;
@property (nonatomic, assign) BOOL isMJPEG;
- (void)clearMessage;
@end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,10 +167,10 @@ - (void)viewDidDisappear:(BOOL)animated {
- (void)dealloc{
[[NSNotificationCenter defaultCenter]removeObserver:self];
[[UIDevice currentDevice]endGeneratingDeviceOrientationNotifications];
[self closeTime];

[self stopCloudPlayMovie];

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

Expand Down Expand Up @@ -375,7 +375,7 @@ - (void)setupUIViews {
if (weakSelf.cloudPlayer.isPlaying == NO) {
[weakSelf tapCloudVideoView:weakSelf.playPauseBtn];
}
[weakSelf startPlayVideoWithStartTime:currentModel.StartTime.integerValue endTime:currentModel.EndTime.integerValue sliderValue:weakSelf.currentTime];
// [weakSelf startPlayVideoWithStartTime:currentModel.StartTime.integerValue endTime:currentModel.EndTime.integerValue sliderValue:weakSelf.currentTime];
}

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

///MARK: 获取mjpeg两路音视频
- (void)getMJPEGVideoURLWithPartURL:(NSString *)videoPartURL withTime:(TIoTDemoCloudEventModel *)timeModel isChangeModel:(BOOL)isChange {
self.videoTimeModel = timeModel;

NSMutableDictionary *paramDic = [[NSMutableDictionary alloc]init];
paramDic[@"ProductId"] = [TIoTCoreAppEnvironment shareEnvironment].cloudProductId?:@"";
paramDic[@"Version"] = @"2021-11-25";
Expand All @@ -547,11 +549,13 @@ - (void)getMJPEGVideoURLWithPartURL:(NSString *)videoPartURL withTime:(TIoTDemoC
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.5 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.cloudPlayer prepareToPlay];
[self.cloudPlayer play];

[self startPlayVideoWithStartTime:self.videoTimeModel.StartTime.integerValue endTime:self.videoTimeModel.EndTime.integerValue sliderValue:0];
self.slider.maximumValue = self.videoTimeModel.EndTime.integerValue - self.videoTimeModel.StartTime.integerValue;
});

[self.cloudAudioPlayer prepareToPlay];
[self.cloudAudioPlayer play];


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

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

//下载下来播放-----start
Expand Down Expand Up @@ -898,6 +902,8 @@ - (void)playVideo:(UIButton *)button {
[self configVideo];
[self.cloudPlayer prepareToPlay];
[self.cloudPlayer play];
[self.cloudAudioPlayer prepareToPlay];
[self.cloudAudioPlayer play];
[self autoHideControlView];

self.cloudIsHidePlayBtn = YES;
Expand All @@ -907,6 +913,8 @@ - (void)playVideo:(UIButton *)button {
[self configVideo];
[self.cloudPlayer prepareToPlay];
[self.cloudPlayer play];
[self.cloudAudioPlayer prepareToPlay];
[self.cloudAudioPlayer play];
[self autoHideControlView];
}
[MBProgressHUD showLodingNoneEnabledInView:self.view withMessage:@""];
Expand Down Expand Up @@ -1273,7 +1281,6 @@ - (void)cloudMoviePlayBackStateDidChange:(NSNotification*)notification
DDLogInfo(@"IJKMPMoviePlayBackStateDidChange %d: playing", (int)_cloudPlayer.playbackState);
if (self.cloudIsPause == NO) {
}
// [self startPlayVideoWithStartTime:self.videoTimeModel.StartTime.integerValue endTime:self.videoTimeModel.EndTime.integerValue sliderValue:self.currentTime];
[MBProgressHUD dismissInView:self.view];
break;
}
Expand All @@ -1300,7 +1307,7 @@ - (void)cloudMoviePlayBackStateDidChange:(NSNotification*)notification

//计时器
- (void)startPlayVideoWithStartTime:(NSInteger )startTime endTime:(NSInteger )endTime sliderValue:(NSInteger)sliderValue{
return;
// return;
if (self.cloudTimer) {
if (self.cloudIsTimerSuspend == YES) {
dispatch_resume(self.cloudTimer);
Expand All @@ -1314,48 +1321,52 @@ - (void)startPlayVideoWithStartTime:(NSInteger )startTime endTime:(NSInteger )en
}
//播放时长 时间戳差值

__weak typeof(self) weakSelf = self;
// __weak typeof(self) weakSelf = self;

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

NSInteger durationValue = self.cloudPlayer.duration;
if (durationValue < 1) {
durationValue = endTime - startTime;
}
NSInteger minuteValue = durationValue / 60;
NSInteger secondValue = durationValue % 60;

self.slider.minimumValue = 0;
self.slider.maximumValue = durationValue;

dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
weakSelf.cloudTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);
self.cloudTimer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0, queue);

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

dispatch_source_set_event_handler(weakSelf.cloudTimer, ^{
dispatch_source_set_event_handler(self.cloudTimer, ^{

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

dispatch_source_cancel(weakSelf.cloudTimer);
dispatch_source_cancel(self.cloudTimer);
dispatch_async(dispatch_get_main_queue(), ^{
[weakSelf stopCloudPlayMovie];
// [weakSelf stopCloudPlayMovie];
//起始时间等于duration
weakSelf.totalLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",minuteValue,secondValue];
weakSelf.currentLabel.text = weakSelf.totalLabel.text;
DDLogDebug(@"over:-----sliderValue:%f---currentTime:%f----totalTime:%f----playduratio:%f",self.slider.value,self.cloudPlayer.currentPlaybackTime,self.cloudPlayer.duration,self.cloudPlayer.playableDuration);
self.totalLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",minuteValue,secondValue];
self.currentLabel.text = self.totalLabel.text;
NSLog(@"over:-----sliderValue:%f---currentTime:%f----totalTime:%f----playduratio:%f",self.slider.value,self.cloudPlayer.currentPlaybackTime,self.cloudPlayer.duration,self.cloudPlayer.playableDuration);
});

}else{

dispatch_async(dispatch_get_main_queue(), ^{
weakSelf.currentLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",time/60,time%60];
weakSelf.totalLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",minuteValue,secondValue];;
weakSelf.slider.value = time;
DDLogDebug(@"duration:-----sliderValue:%f---currentTime:%f----totalTime:%f----playduratio:%f",self.slider.value,self.cloudPlayer.currentPlaybackTime,self.cloudPlayer.duration,self.cloudPlayer.playableDuration);
self.slider.maximumValue = durationValue;
self.currentLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",time/60,time%60];
self.totalLabel.text = [NSString stringWithFormat:@"%02ld:%02ld",minuteValue,secondValue];;
self.slider.value = (float)time;
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);
});
time++;

}
});
dispatch_resume(weakSelf.cloudTimer);
dispatch_resume(self.cloudTimer);
}

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


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

- (void)stopCloudPlayMovie {
[self.cloudPlayer stop];
self.cloudPlayer = nil;

[self.cloudAudioPlayer stop];
self.cloudAudioPlayer = nil;
if (self.cloudPlayer != nil) {
[self.cloudPlayer stop];
[self.cloudPlayer.view removeFromSuperview];
self.cloudPlayer = nil;
}
if (self.cloudAudioPlayer != nil) {
[self.cloudAudioPlayer stop];
[self.cloudAudioPlayer.view removeFromSuperview];
self.cloudAudioPlayer = nil;
}
}

#pragma mark - lazy loading
Expand Down
1 change: 1 addition & 0 deletions Source/LinkSDKDemo/Video/PlayBack/TIoTDemoPlaybackVC.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ typedef void(^TIoTDemoPlayerReloadBlock)(void);
@property (nonatomic, copy) NSString *deviceName;
@property (nonatomic, assign) BOOL isFromHome;
@property (nonatomic, strong) NSString *device_xp2p_info;
@property (nonatomic, assign) BOOL isMJPEG;
@end

NS_ASSUME_NONNULL_END
1 change: 1 addition & 0 deletions Source/LinkSDKDemo/Video/PlayBack/TIoTDemoPlaybackVC.m
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,7 @@ - (NSArray *)childControllers {
if (!_childControllers) {

self.cloudStorageVC = [[TIoTCloudStorageVC alloc]init];
self.cloudStorageVC.isMJPEG = self.isMJPEG;
self.localRecordVC = [[TIoTDemoLocalRecordVC alloc]init];

self.cloudStorageVC.title = @"云记录";
Expand Down

0 comments on commit ec26b61

Please sign in to comment.