| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- //
- // ZFCustomControlViewViewController.m
- // ZFPlayer_Example
- //
- // Created by 紫枫 on 2019/6/5.
- // Copyright © 2019 紫枫. All rights reserved.
- //
- #import "ZFCustomControlViewViewController.h"
- #import "ZFCustomControlView.h"
- #import <ZFPlayer/ZFAVPlayerManager.h>
- #import <ZFPlayer/ZFIJKPlayerManager.h>
- #import <ZFPlayer/ZFPlayerControlView.h>
- #import <ZFPlayer/UIView+ZFFrame.h>
- #import <ZFPlayer/ZFPlayerConst.h>
- #import "UIImageView+ZFCache.h"
- #import "ZFUtilities.h"
- static NSString *kVideoCover = @"https://upload-images.jianshu.io/upload_images/635942-14593722fe3f0695.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240";
- @interface ZFCustomControlViewViewController ()
- @property (nonatomic, strong) ZFPlayerController *player;
- @property (nonatomic, strong) UIImageView *containerView;
- @property (nonatomic, strong) ZFCustomControlView *controlView;
- @end
- @implementation ZFCustomControlViewViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- self.view.backgroundColor = [UIColor whiteColor];
- [self.view addSubview:self.containerView];
-
- ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
- /// 播放器相关
- self.player = [ZFPlayerController playerWithPlayerManager:playerManager containerView:self.containerView];
- self.player.controlView = self.controlView;
- /// 设置退到后台继续播放
- self.player.pauseWhenAppResignActive = NO;
-
- @zf_weakify(self)
- /// 播放完成
- self.player.playerDidToEnd = ^(id _Nonnull asset) {
- @zf_strongify(self)
- [self.player.currentPlayerManager replay];
- [self.player playTheNext];
- if (!self.player.isLastAssetURL) {
- NSString *title = [NSString stringWithFormat:@"视频标题%zd",self.player.currentPlayIndex];
- [self.controlView showTitle:title coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeLandscape];
- } else {
- [self.player stop];
- }
- };
-
- playerManager.assetURL = [NSURL URLWithString:@"https://www.apple.com/105/media/cn/mac/family/2018/46c4b917_abfd_45a3_9b51_4e3054191797/films/bruce/mac-bruce-tpl-cn-2018_1280x720h.mp4"];
- [self.controlView showTitle:@"自定义控制层" coverURLString:kVideoCover fullScreenMode:ZFFullScreenModeAutomatic];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- self.player.viewControllerDisappear = NO;
- }
- - (void)viewWillDisappear:(BOOL)animated {
- [super viewWillDisappear:animated];
- self.player.viewControllerDisappear = YES;
- }
- - (void)viewWillLayoutSubviews {
- [super viewWillLayoutSubviews];
- CGFloat x = 0;
- CGFloat y = CGRectGetMaxY(self.navigationController.navigationBar.frame);
- CGFloat w = CGRectGetWidth(self.view.frame);
- CGFloat h = w*9/16;
- self.containerView.frame = CGRectMake(x, y, w, h);
- }
- - (UIStatusBarStyle)preferredStatusBarStyle {
- return UIStatusBarStyleDefault;
- }
- - (BOOL)prefersStatusBarHidden {
- return NO;
- }
- - (BOOL)shouldAutorotate {
- return NO;
- }
- - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
- if (self.player.isFullScreen) {
- return UIInterfaceOrientationMaskLandscape;
- }
- return UIInterfaceOrientationMaskPortrait;
- }
- - (ZFCustomControlView *)controlView {
- if (!_controlView) {
- _controlView = [ZFCustomControlView new];
- }
- return _controlView;
- }
- - (UIImageView *)containerView {
- if (!_containerView) {
- _containerView = [UIImageView new];
- [_containerView setImageWithURLString:kVideoCover placeholder:[ZFUtilities imageWithColor:[UIColor colorWithRed:220/255.0 green:220/255.0 blue:220/255.0 alpha:1] size:CGSizeMake(1, 1)]];
- }
- return _containerView;
- }
- @end
|