videoPlayByAVPlayerViewController.m 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  1. //
  2. // videoPlayByAVPlayerViewController.m
  3. // 双子星云手机
  4. //
  5. // Created by xd h on 2024/5/22.
  6. //
  7. #import "videoPlayByAVPlayerViewController.h"
  8. #import "ZFCustomControlView.h"
  9. #import <ZFPlayer/ZFAVPlayerManager.h>
  10. #import <ZFPlayer/ZFIJKPlayerManager.h>
  11. #import <ZFPlayer/ZFPlayerControlView.h>
  12. #import <ZFPlayer/UIView+ZFFrame.h>
  13. #import <ZFPlayer/ZFPlayerConst.h>
  14. #import "UIImageView+ZFCache.h"
  15. #import "ZFUtilities.h"
  16. @interface videoPlayByAVPlayerViewController ()
  17. @property (nonatomic, strong) ZFPlayerController *player;
  18. @property (nonatomic, strong) ZFAVPlayerManager *playerManager;
  19. @property (nonatomic, strong) UIImageView *containerView;
  20. @property (nonatomic, strong) ZFCustomControlView *controlView;
  21. @end
  22. @implementation videoPlayByAVPlayerViewController
  23. - (void)viewDidLoad {
  24. [super viewDidLoad];
  25. // Do any additional setup after loading the view.
  26. [self.toolBar setHidden:YES];
  27. [self.navigationBar setHidden:YES];
  28. [self.navBarBGView setHidden:NO];
  29. //self.navBarBGView.backgroundColor = [UIColor whiteColor];
  30. [self.view setBackgroundColor:[UIColor whiteColor]];
  31. [self.view addSubview:self.containerView];
  32. self.playerManager = [[ZFAVPlayerManager alloc] init];
  33. /// 播放器相关
  34. self.player = [ZFPlayerController playerWithPlayerManager:self.playerManager containerView:self.containerView];
  35. self.player.controlView = self.controlView;
  36. /// 设置退到后台继续播放
  37. self.player.pauseWhenAppResignActive = NO;
  38. @zf_weakify(self)
  39. /// 播放完成
  40. self.player.playerDidToEnd = ^(id _Nonnull asset) {
  41. @zf_strongify(self)
  42. [self.player.currentPlayerManager replay];
  43. [self.player playTheNext];
  44. if (!self.player.isLastAssetURL) {
  45. NSString *title = [NSString stringWithFormat:@"视频标题%zd",self.player.currentPlayIndex];
  46. [self.controlView showTitle:title coverURLString:nil fullScreenMode:ZFFullScreenModeLandscape];
  47. } else {
  48. [self.player stop];
  49. }
  50. };
  51. [self.controlView showTitle:@"自定义控制层" coverURLString:nil fullScreenMode:ZFFullScreenModeAutomatic];
  52. }
  53. - (void)viewWillAppear:(BOOL)animated {
  54. [super viewWillAppear:animated];
  55. self.player.viewControllerDisappear = NO;
  56. //http://transfertest.armclouding.com:10006/getFile?path=/storage/C47D-46D2/3907638929_%E6%98%8E%E9%81%93.MP4
  57. //http://transfertest.armclouding.com:10006/getFile?path=/storage/C47D-46D2/mp4/loginVideo.mp4
  58. NSString *filePath = _VideoDataMode.path;
  59. NSString *urlStr = ksharedAppDelegate.NASFileService;
  60. NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
  61. fileUrl = @"http://transfertest.armclouding.com:10010/getFile?path=/sdcard/bb.mp4";
  62. fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  63. NSURL * sourceMovieURL= [NSURL URLWithString:fileUrl];
  64. self.playerManager.assetURL = sourceMovieURL;
  65. }
  66. - (void)viewWillDisappear:(BOOL)animated {
  67. [super viewWillDisappear:animated];
  68. self.player.viewControllerDisappear = YES;
  69. }
  70. - (void)viewWillLayoutSubviews {
  71. [super viewWillLayoutSubviews];
  72. CGFloat x = 0;
  73. CGFloat y = CGRectGetMaxY(self.navigationController.navigationBar.frame);
  74. CGFloat w = CGRectGetWidth(self.view.frame);
  75. CGFloat h = w*9/16;
  76. self.containerView.frame = CGRectMake(x, y, w, h);
  77. }
  78. - (UIStatusBarStyle)preferredStatusBarStyle {
  79. return UIStatusBarStyleDefault;
  80. }
  81. - (BOOL)prefersStatusBarHidden {
  82. return NO;
  83. }
  84. - (BOOL)shouldAutorotate {
  85. return NO;
  86. }
  87. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  88. if (self.player.isFullScreen) {
  89. return UIInterfaceOrientationMaskLandscape;
  90. }
  91. return UIInterfaceOrientationMaskPortrait;
  92. }
  93. - (ZFCustomControlView *)controlView {
  94. if (!_controlView) {
  95. _controlView = [ZFCustomControlView new];
  96. }
  97. return _controlView;
  98. }
  99. - (UIImageView *)containerView {
  100. if (!_containerView) {
  101. _containerView = [UIImageView new];
  102. [_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)]];
  103. }
  104. return _containerView;
  105. }
  106. @end