123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135 |
- //
- // videoPlayByAVPlayerViewController.m
- // 双子星云手机
- //
- // Created by xd h on 2024/5/22.
- //
- #import "videoPlayByAVPlayerViewController.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"
- @interface videoPlayByAVPlayerViewController ()
- @property (nonatomic, strong) ZFPlayerController *player;
- @property (nonatomic, strong) ZFAVPlayerManager *playerManager;
- @property (nonatomic, strong) UIImageView *containerView;
- @property (nonatomic, strong) ZFCustomControlView *controlView;
- @end
- @implementation videoPlayByAVPlayerViewController
- - (void)viewDidLoad {
- [super viewDidLoad];
- // Do any additional setup after loading the view.
-
- [self.toolBar setHidden:YES];
- [self.navigationBar setHidden:YES];
- [self.navBarBGView setHidden:NO];
- //self.navBarBGView.backgroundColor = [UIColor whiteColor];
- [self.view setBackgroundColor:[UIColor whiteColor]];
-
- [self.view addSubview:self.containerView];
- self.playerManager = [[ZFAVPlayerManager alloc] init];
- /// 播放器相关
- self.player = [ZFPlayerController playerWithPlayerManager:self.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:nil fullScreenMode:ZFFullScreenModeLandscape];
- } else {
- [self.player stop];
- }
- };
-
-
- [self.controlView showTitle:@"自定义控制层" coverURLString:nil fullScreenMode:ZFFullScreenModeAutomatic];
- }
- - (void)viewWillAppear:(BOOL)animated {
- [super viewWillAppear:animated];
- self.player.viewControllerDisappear = NO;
-
- //http://transfertest.armclouding.com:10006/getFile?path=/storage/C47D-46D2/3907638929_%E6%98%8E%E9%81%93.MP4
- //http://transfertest.armclouding.com:10006/getFile?path=/storage/C47D-46D2/mp4/loginVideo.mp4
-
- NSString *filePath = _VideoDataMode.path;
- NSString *urlStr = ksharedAppDelegate.NASFileService;
- NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
-
- fileUrl = @"http://transfertest.armclouding.com:10010/getFile?path=/sdcard/bb.mp4";
- fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
-
- NSURL * sourceMovieURL= [NSURL URLWithString:fileUrl];
-
- self.playerManager.assetURL = sourceMovieURL;
- }
- - (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:nil 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
|