// // RQVideoModule.m // SDJK // // Created by 张嵘 on 2021/10/25. // #import "RQVideoModule.h" /// 播放视频 NSString * const RQPlayVideoUrlNotification = @"RQPlayVideoUrlNotification"; /// 播放视频Model NSString * const RQPlayVideoItemKey = @"RQPlayVideoItemKey"; /// 播放视频ModelArr NSString * const RQPlayVideoItemArrKey = @"RQPlayVideoItemArrKey"; /// 视频Index NSString * const RQVideoItemIndexKey = @"RQVideoItemIndexKey"; /// 视频IndexPath NSString * const RQVideoItemIndexPathKey = @"RQVideoItemIndexPathKey"; @interface RQVideoModule () @property (nonatomic, readwrite, strong) ZFPlayerControlView *controlView; @property (nonatomic, readwrite, assign) RQADDoType adDoType; @property (nonatomic, readwrite, assign) ZFPlayerPlaybackState playState; @property (nonatomic, readwrite, assign) BOOL isShow; @property (nonatomic, readwrite, assign) BOOL isSH; @property (nonatomic, readwrite, strong) RQVipPlaceHolderView *vipPlaceHolderView; @end @implementation RQVideoModule @def_singleton(RQVideoModule); - (BOOL)isCanWatchWithVideosItem:(VideosItem *)videosItem { @weakify(self) [RQ_COMMON_MANAGER checkVersionWithComplete:^(BOOL isSH) { @strongify(self) self.isSH = isSH; }]; return YES; } - (void)playVideoWithVideosItem:(VideosItem *)videosItem videosItemArr:(NSArray *)videosItemArr playView:(UIView *)playView scrollView:(UIScrollView *)scrollView { if (self.playerController && self.playerController.isPlaying) { [self.playerController stop]; self.playerController = [[MPPlayerController alloc] initWithContainerView:playView]; [self requestDataWithVideosItem:videosItem videosItemArr:videosItemArr playView:playView scrollView:scrollView]; } else { self.playerController = [[MPPlayerController alloc] initWithContainerView:playView]; [self requestDataWithVideosItem:videosItem videosItemArr:videosItemArr playView:playView scrollView:scrollView]; } } - (void)requestDataWithVideosItem:(VideosItem *)videoItem videosItemArr:(NSArray *)videosItemArr playView:(UIView *)playView scrollView:(UIScrollView *)scrollView { @weakify(self) if (RQ_Video_Module.currentpPlayVideosItem.isPlaying) { RQ_Video_Module.currentpPlayVideosItem.isPlaying = NO; } [self.playerController.player setExitFullScreenWhenStop:NO]; self.playerController.playableArray = videosItemArr; self.playerController.controlView = self.controlView; [self.controlView showTitle:videoItem.title coverURLString:videoItem.coverFileUrl placeholderImage:RQWebVideoImagePlaceholder() fullScreenMode:ZFFullScreenModeAutomatic]; [self.playerController playWithPlayable:videoItem]; [self.playerController.currentPlayerManager pause]; [RQ_AD_MANAGER loadAdWithAdType:RQADType_native customView:playView]; [RQ_AD_MANAGER initCloseBlock:^(RQADDoType adDoType) { self.adDoType = adDoType; ZFPlayerPlaybackState playState = self.playerController.currentPlayerManager.playState; if (adDoType == RQADDoType_Miss) { } switch (adDoType) { case RQADDoType_Success: case RQADDoType_Click:{ if (playState == ZFPlayerPlayStatePlaying) { [self.playerController.currentPlayerManager pause]; } break; } case RQADDoType_Faild: case RQADDoType_Close:{ if (playState == ZFPlayerPlayStatePaused) { NSLog(@"%@",NSStringFromClass([RQControllerHelper.currentViewController class])); if (!self.playerController.player.isFullScreen) { [self.playerController.currentPlayerManager play]; self.adDoType = RQADDoType_Miss; } else { if ([NSStringFromClass([RQControllerHelper.currentViewController class]) isEqualToString:@"ZFLandscapeViewController"]) { [self.playerController.currentPlayerManager play]; self.adDoType = RQADDoType_Miss; } else { } } } break; } default: break; } }]; self.playerController.player.playerPlayTimeChanged = ^(id _Nonnull asset, NSTimeInterval currentTime, NSTimeInterval duration) { @strongify(self) if (self.isSH) { /// } else { if (RQ_USER_MANAGER.isVip <= 0) { if (self.playerController.player.currentTime >= 15) { [self.playerController.currentPlayerManager pause]; if ([RQ_USER_MANAGER isShouldLogin]) { [self.playerController.containerView addSubview:self.vipPlaceHolderView]; [self.vipPlaceHolderView.reLookBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { [self.vipPlaceHolderView removeFromSuperview]; self.controlView = nil; self.playerController.controlView = self.controlView; [self.controlView showTitle:videoItem.title coverURLString:videoItem.coverFileUrl placeholderImage:RQWebVideoImagePlaceholder() fullScreenMode:ZFFullScreenModeAutomatic]; [self.playerController playWithPlayable:videoItem]; }]; } } } } }; self.playerController.currentPlayerManager.playerDidToEnd = ^(id _Nonnull asset) { @strongify(self) if (!self.playerController.player.isFullScreen) { NSInteger currentIndex = [videosItemArr indexOfObject:videoItem]; NSInteger nextIndex = (currentIndex + 1 >= self.playerController.playableArray.count)? 0 : currentIndex + 1; VideosItem *nextVideoItem = (VideosItem *)videosItemArr[nextIndex]; if ([self isCanWatchWithVideosItem:nextVideoItem]) { videoItem.isPlaying = NO; nextVideoItem.isPlaying = YES; [self playVideoWithVideosItem:nextVideoItem videosItemArr:videosItemArr playView:playView scrollView:scrollView]; [scrollView zf_scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:nextIndex inSection:0] atScrollPosition:ZFPlayerScrollViewScrollPositionCenteredVertically animated:YES completionHandler:nil]; } } else { NSInteger currentIndex = [videosItemArr indexOfObject:RQ_Video_Module.currentpPlayVideosItem]; NSInteger nextIndex = (currentIndex + 1 >= self.playerController.playableArray.count)? 0 : currentIndex + 1; VideosItem *nextVideoItem = (VideosItem *)videosItemArr[nextIndex]; if ([self isCanWatchWithVideosItem:nextVideoItem]) { [RQ_AD_MANAGER loadAdWithAdType:RQADType_fullScreen customView:nil]; __block BOOL isSure; SCLAlertView *alert = [[SCLAlertView alloc] initWithNewWindow]; alert.backgroundViewColor = RQ_BACKGROUNDCOLOR_1; alert.customViewColor = RQ_MAIN_COLOR; [alert addButton:@"立即播放 " actionBlock:^(void) { isSure = YES; RQ_Video_Module.currentpPlayVideosItem.isPlaying = NO; [self.playerController playWithPlayable:nextVideoItem]; nextVideoItem.isPlaying = YES; [self.playerController.currentPlayerManager pause]; [self.controlView updateTitle:nextVideoItem.title coverURLString:nextVideoItem.coverFileUrl placeholderImage:RQWebVideoImagePlaceholder() fullScreenMode:ZFFullScreenModeAutomatic]; RQ_Video_Module.currentpPlayVideosItem = nextVideoItem; }]; [alert addTimerToButtonIndex:0 reverse:YES]; [alert showNotice:@"温馨提示" subTitle:@"即将播放下一个视频" closeButtonTitle:@"取消" duration:5.0f]; [alert alertIsDismissed:^{ if (isSure) { [RQ_AD_MANAGER showAdWithAdType:RQADType_fullScreen]; } }]; } } }; //延时 [[[RACSignal createSignal:^RACDisposable *(id subscriber) { [subscriber sendNext:@"延时1.f秒"]; return nil; }] delay:1.f] subscribeNext:^(id x) { NSInteger index = [videosItemArr indexOfObject:videoItem]; [scrollView zf_scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:index inSection:0] atScrollPosition:ZFPlayerScrollViewScrollPositionCenteredVertically animated:YES completionHandler:nil]; }]; videoItem.isPlaying = YES; RQ_Video_Module.currentpPlayVideosItem = videoItem; } #pragma mark - LazyLoad - (ZFPlayerControlView *)controlView { if (!_controlView) { _controlView = [[ZFPlayerControlView alloc] init]; @weakify(self) [_controlView.portraitControlView.backBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { @strongify(self) [self.playerController stop]; [RQ_APPDELEGATE.services popViewModelAnimated:YES]; }]; } return _controlView; } - (RQVipPlaceHolderView *)vipPlaceHolderView { if (!_vipPlaceHolderView) { _vipPlaceHolderView = [RQVipPlaceHolderView vipPlaceHolderView]; _vipPlaceHolderView.size = self.playerController.containerView.size; [_vipPlaceHolderView.openBtn setTapActionWithBlock:^(UITapGestureRecognizer *tap) { [RQ_APPDELEGATE.services pushViewModel:[[RQActivateVIPViewModel alloc] initWithServices:RQ_APPDELEGATE.services params:nil] animated:YES]; }]; } return _vipPlaceHolderView; } @end