123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162 |
- //
- // HomeSchollVideoVC.m
- // smartRhino
- //
- // Created by niuzhen on 2020/5/18.
- // Copyright © 2020 tederen. All rights reserved.
- //
- #import "HomeSchollVideoVC.h"
- #import <ZFPlayer/ZFAVPlayerManager.h>
- #import <ZFPlayer/ZFPlayerControlView.h>
- @interface HomeSchollVideoVC ()
- @property (nonatomic, strong) ZFPlayerController *player;
- @property (nonatomic, strong) UIImageView *containerView;
- @property (nonatomic, strong) ZFPlayerControlView *controlView;
- @property (nonatomic, strong) UIButton *playBtn;
- @property (nonatomic, assign) BOOL isPlay;
- @property (nonatomic, strong) NSMutableArray <NSURL *>*assetURLs;
- @end
- @implementation HomeSchollVideoVC
- +(HomeSchollVideoVC *)initHomeSchollVideoVC{
- HomeSchollVideoVC *controller = [StoryboardManager.shared.home instantiateViewControllerWithIdentifier:@"HomeSchollVideoVC"];
- return controller;
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- [self.assetURLs removeAllObjects];
- self.player.viewControllerDisappear = NO;
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- [self.assetURLs removeAllObjects];
- [self.player stop];
- self.player.viewControllerDisappear = YES;
- }
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.fd_prefersNavigationBarHidden = YES;
- [self setupPlayer];
- }
- - (void)setupPlayer
- {
- [self.view addSubview:self.containerView];
- [self.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.mas_equalTo(self.view);
- make.size.mas_offset(CGSizeMake(SCREEN_WIDTH, SCREEN_WIDTH / 16 * 9));
- }];
- ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
- playerManager.shouldAutoPlay = YES;
- [self.containerView sd_setImageWithURL:[NSURL URLWithString:self.VideoImage]];
- /// 播放器相关
- self.player = [ZFPlayerController playerWithPlayerManager:playerManager containerView:self.containerView];
- self.player.controlView = self.controlView;
- [self.containerView addSubview:self.playBtn];
- [self.playBtn mas_makeConstraints:^(MASConstraintMaker *make) {
- make.center.mas_equalTo(self.containerView);
- }];
- /// 设置退到后台继续播放
- self.player.pauseWhenAppResignActive = NO;
- // self.player.resumePlayRecord = YES;
- // self.player.lockedScreen = YES;
- // self.player.allowOrentitaionRotation = NO;
- // [self.player enterFullScreen:YES animated:NO];
- WS(weakSelf);
- self.player.orientationWillChange = ^(ZFPlayerController * _Nonnull player, BOOL isFullScreen) {
- ((AppDelegate *)[[UIApplication sharedApplication] delegate]).allowOrentitaionRotation = isFullScreen;
- };
-
- /// 播放完成
- self.player.playerDidToEnd = ^(id _Nonnull asset) {
- if (!weakSelf.player.isLastAssetURL) {
- [weakSelf.player playTheNext];
- NSString *title = [NSString stringWithFormat:@"视频标题%zd",weakSelf.player.currentPlayIndex];
- [weakSelf.controlView showTitle:title coverURLString:weakSelf.file fullScreenMode:ZFFullScreenModeLandscape];
- } else {
- [weakSelf.player stop];
- }
- };
- [self.assetURLs addObject:[NSURL URLWithString:weakSelf.file]];
- self.player.assetURLs = self.assetURLs;
- [self.player playTheIndex:0];
- [self.controlView showTitle:@"" coverURLString:weakSelf.file fullScreenMode:ZFFullScreenModeAutomatic];
- [self.playBtn setAction:^{
- weakSelf.isPlay = !weakSelf.isPlay;
- if (weakSelf.isPlay) {
- weakSelf.player.currentPlayIndex = 0;
- [weakSelf.player playTheNext];
- [weakSelf.playBtn setImage:IMG(@"new_allPause_44x44_") forState:UIControlStateNormal];
- }else{
- [weakSelf.player stop];
- [weakSelf.playBtn setImage:IMG(@"new_allPlay_44x44_") forState:UIControlStateNormal];
- }
- }];
- // self.controlView.backBtnClickCallback = ^{
- // [weakSelf.navigationController popViewControllerAnimated:YES];
- // };
- }
- #pragma mark - ZFPlayer
- - (UIStatusBarStyle)preferredStatusBarStyle {
- return UIStatusBarStyleDefault;
- }
- - (BOOL)prefersStatusBarHidden {
- return NO;
- }
- - (UIStatusBarAnimation)preferredStatusBarUpdateAnimation {
- return UIStatusBarAnimationNone;
- }
- - (BOOL)shouldAutorotate {
- return NO;
- }
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
- return UIInterfaceOrientationMaskLandscapeLeft;
- }
- - (ZFPlayerControlView *)controlView {
- if (!_controlView) {
- _controlView = [ZFPlayerControlView new];
- _controlView.fastViewAnimated = YES;
- _controlView.autoHiddenTimeInterval = 5;
- _controlView.autoFadeTimeInterval = 0.5;
- _controlView.prepareShowLoading = YES;
- _controlView.prepareShowControlView = NO;
- _controlView.fullScreenMode = ZFFullScreenModeLandscape;
- }
- return _controlView;
- }
- - (UIImageView *)containerView {
- if (!_containerView) {
- CGFloat h = SCREEN_WIDTH*9/16;
- _containerView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, h)];
- }
- return _containerView;
- }
- - (UIButton *)playBtn {
- if (!_playBtn) {
- _playBtn = [UIButton buttonWithType:UIButtonTypeCustom];
- [_playBtn setImage:IMG(@"new_allPause_44x44_") forState:UIControlStateNormal];
- }
- return _playBtn;
- }
- - (NSMutableArray<NSURL *> *)assetURLs {
- if (!_assetURLs) {
- _assetURLs = [NSMutableArray array];
- }
- return _assetURLs;
- }
- @end
|