@@ -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
0 commit comments