videoPlayByAVPlayerViewController.m 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  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.containerView mas_makeConstraints:^(MASConstraintMaker *make) {
  33. make.left.mas_equalTo(0);
  34. make.right.mas_equalTo(0);
  35. make.bottom.mas_equalTo(0);
  36. make.top.mas_equalTo(self.navBarBGView.mas_bottom);
  37. }];
  38. self.playerManager = [[ZFAVPlayerManager alloc] init];
  39. /// 播放器相关
  40. self.player = [ZFPlayerController playerWithPlayerManager:self.playerManager containerView:self.containerView];
  41. self.player.controlView = self.controlView;
  42. /// 设置退到后台继续播放
  43. self.player.pauseWhenAppResignActive = NO;
  44. @zf_weakify(self)
  45. /// 播放完成
  46. self.player.playerDidToEnd = ^(id _Nonnull asset) {
  47. @zf_strongify(self)
  48. //[self.player.currentPlayerManager replay];
  49. [self.player playTheNext];
  50. if (!self.player.isLastAssetURL) {
  51. // NSString *title = [NSString stringWithFormat:@"视频标题%zd",self.player.currentPlayIndex];
  52. // [self.controlView showTitle:title coverURLString:nil fullScreenMode:ZFFullScreenModeLandscape];
  53. } else {
  54. [self.player stop];
  55. }
  56. };
  57. self.player.playerPlayFailed = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, id _Nonnull error) {
  58. HLog(@"%@----%@",asset,error);
  59. };
  60. }
  61. - (void)viewWillAppear:(BOOL)animated {
  62. [super viewWillAppear:animated];
  63. self.player.viewControllerDisappear = NO;
  64. //http://transfertest.armclouding.com:10006/getFile?path=/storage/C47D-46D2/3907638929_%E6%98%8E%E9%81%93.MP4
  65. //http://transfertest.armclouding.com:10006/getFile?path=/storage/C47D-46D2/mp4/loginVideo.mp4
  66. if(!self.playerManager.assetURL){
  67. NSString *filePath = _VideoDataMode.path;
  68. NSString *urlStr = ksharedAppDelegate.NASFileService;
  69. NSString *fileUrl = [[NSString alloc] initWithFormat:@"%@getFile?path=%@",urlStr,filePath];
  70. NSString *showUrl = [[NSString alloc] initWithFormat:@"%@getThumbnail?path=%@",urlStr,filePath];
  71. //HLog(@"%@",fileUrl);
  72. //fileUrl = @"http://transfertest.armclouding.com:10010/getFile?path=/sdcard/bb.mp4";
  73. //fileUrl = @"http://m10.music.126.net/20240527160012/d3f165dc686ac01afd4497400b2c2c58/ymusic/5353/0f0f/0358/d99739615f8e5153d77042092f07fd77.mp3";
  74. fileUrl = [fileUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
  75. NSURL * sourceMovieURL= [NSURL URLWithString:fileUrl];
  76. self.playerManager.assetURL = sourceMovieURL;
  77. self.titleLabel.text = _VideoDataMode.name;
  78. [self.controlView showTitle:@"" coverURLString:showUrl fullScreenMode:ZFFullScreenModeAutomatic];
  79. }
  80. }
  81. - (void)viewWillDisappear:(BOOL)animated {
  82. [super viewWillDisappear:animated];
  83. self.player.viewControllerDisappear = YES;
  84. }
  85. - (void)viewWillLayoutSubviews {
  86. [super viewWillLayoutSubviews];
  87. CGFloat x = 0;
  88. CGFloat y = CGRectGetMaxY(self.navigationController.navigationBar.frame);
  89. CGFloat w = CGRectGetWidth(self.view.frame);
  90. CGFloat h = w*9/16;
  91. self.containerView.frame = CGRectMake(x, y, w, h);
  92. }
  93. - (UIStatusBarStyle)preferredStatusBarStyle {
  94. return UIStatusBarStyleDefault;
  95. }
  96. - (BOOL)prefersStatusBarHidden {
  97. return NO;
  98. }
  99. - (BOOL)shouldAutorotate {
  100. return NO;
  101. }
  102. - (UIInterfaceOrientationMask)supportedInterfaceOrientations {
  103. if (self.player.isFullScreen) {
  104. return UIInterfaceOrientationMaskLandscape;
  105. }
  106. return UIInterfaceOrientationMaskPortrait;
  107. }
  108. - (ZFCustomControlView *)controlView {
  109. if (!_controlView) {
  110. _controlView = [ZFCustomControlView new];
  111. }
  112. return _controlView;
  113. }
  114. - (UIImageView *)containerView {
  115. if (!_containerView) {
  116. _containerView = [UIImageView new];
  117. [_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)]];
  118. }
  119. return _containerView;
  120. }
  121. @end