ShowDetailVC.m 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153
  1. //
  2. // ShowDetailVC.m
  3. // live1v1
  4. //
  5. // Created by ybRRR on 2019/8/2.
  6. // Copyright © 2019 IOS1. All rights reserved.
  7. //
  8. #import "ShowDetailVC.h"
  9. #import <ZFPlayer/ZFPlayer.h>
  10. #import <ZFPlayer/ZFAVPlayerManager.h>
  11. #import <ZFPlayer/ZFIJKPlayerManager.h>
  12. #import <ZFPlayer/ZFPlayerControlView.h>
  13. #import "YBGoodPlayerCtrView.h"
  14. @interface ShowDetailVC ()
  15. {
  16. UIImageView *playVideoImg;
  17. UIImageView *_pauseIV;
  18. }
  19. @property (nonatomic, strong) ZFPlayerController *player;
  20. @property(nonatomic,strong)YBGoodPlayerCtrView *controlView;
  21. @end
  22. @implementation ShowDetailVC
  23. -(void)viewWillDisappear:(BOOL)animated{
  24. [super viewWillDisappear:YES];
  25. if (self.player) {
  26. self.player.viewControllerDisappear = YES;
  27. }
  28. }
  29. - (void)viewDidAppear:(BOOL)animated{
  30. [super viewDidAppear:animated];
  31. if (self.player) {
  32. self.player.viewControllerDisappear = NO;
  33. }
  34. }
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. self.view.backgroundColor = [UIColor whiteColor];
  38. self.navigationController.navigationBar.hidden = YES;
  39. UIButton *returnBtn = [UIButton buttonWithType:0];
  40. returnBtn.frame = CGRectMake(12, 22+statusbarHeight, 40, 40);
  41. [returnBtn setImage:[UIImage imageNamed:@"pub_back"] forState:0];
  42. [returnBtn addTarget:self action:@selector(returnBtnClick) forControlEvents:UIControlEventTouchUpInside];
  43. playVideoImg = [[UIImageView alloc]init];
  44. playVideoImg.frame = CGRectMake(0, 0, _window_width, _window_height);
  45. if (_thumbImg) {
  46. playVideoImg.image = _thumbImg;
  47. }
  48. [self.view addSubview:playVideoImg];
  49. [self.view sendSubviewToBack:playVideoImg];
  50. [self.view addSubview:returnBtn];
  51. NSURL *pathUrl = [NSURL URLWithString:self.videoPath];
  52. if (![self.videoPath containsString:@"http"]) {
  53. pathUrl = [NSURL fileURLWithPath:self.videoPath isDirectory:NO];
  54. }
  55. [self initPlayer];
  56. }
  57. -(void)returnBtnClick{
  58. [[YBBaseAppDelegate sharedAppDelegate]popViewController:YES];
  59. }
  60. -(void)deleteClick{
  61. UIAlertController *alertContro = [UIAlertController alertControllerWithTitle:nil message:YZMsg(@"要删除此视频吗?") preferredStyle:UIAlertControllerStyleActionSheet];
  62. UIAlertAction *cancleAction = [UIAlertAction actionWithTitle:YZMsg(@"取消") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  63. }];
  64. [alertContro addAction:cancleAction];
  65. UIAlertAction *sureAction = [UIAlertAction actionWithTitle:YZMsg(@"删除") style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {
  66. if (self.deleteEvent) {
  67. self.deleteEvent(@"视频");
  68. }
  69. [[YBBaseAppDelegate sharedAppDelegate]popViewController:YES];
  70. }];
  71. [sureAction setValue:[UIColor redColor] forKey:@"_titleTextColor"];
  72. [alertContro addAction:sureAction];
  73. [self presentViewController:alertContro animated:YES completion:nil];
  74. }
  75. -(void)initPlayer {
  76. if (self.player) {
  77. return;
  78. }
  79. ZFAVPlayerManager *playerManager = [[ZFAVPlayerManager alloc] init];
  80. // playerManager.requestHeader = @{@"Referer":h5url};
  81. NSDictionary *header = @{@"Referer":h5url};
  82. NSDictionary *optiosDic = @{@"AVURLAssetHTTPHeaderFieldsKey" : header};
  83. [playerManager setRequestHeader:optiosDic];
  84. /// player的tag值必须在cell里设置
  85. self.player = [ZFPlayerController playerWithPlayerManager:playerManager containerView:playVideoImg];
  86. self.player.controlView = self.controlView;
  87. //[self.player setDisableGestureTypes:ZFPlayerDisableGestureTypesAll];
  88. self.player.currentPlayerManager.scalingMode = ZFPlayerScalingModeAspectFill;
  89. /// 竖屏的全屏
  90. self.player.orientationObserver.fullScreenMode = ZFFullScreenModePortrait;
  91. /*
  92. /// 隐藏全屏的状态栏
  93. self.player.orientationObserver.fullScreenStatusBarHidden = YES;
  94. self.player.orientationObserver.fullScreenStatusBarAnimation = UIStatusBarAnimationNone;
  95. /// 全屏的填充模式(全屏填充、按视频大小填充)
  96. self.player.orientationObserver.portraitFullScreenMode = ZFPortraitFullScreenModeScaleAspectFit;
  97. /// 禁用竖屏全屏的手势(点击、拖动手势)
  98. self.player.orientationObserver.disablePortraitGestureTypes = ZFDisablePortraitGestureTypesNone;
  99. */
  100. self.player.playerDisapperaPercent = 1.0;
  101. NSURL *pathUrl = [NSURL URLWithString:self.videoPath];
  102. if (![self.videoPath containsString:@"http"]) {
  103. pathUrl = [NSURL fileURLWithPath:self.videoPath isDirectory:NO];
  104. }
  105. self.player.assetURL = pathUrl;
  106. //功能
  107. self.player.playerPrepareToPlay = ^(id<ZFPlayerMediaPlayback> _Nonnull asset, NSURL * _Nonnull assetURL) {
  108. NSLog(@"准备");
  109. };
  110. YBWeakSelf;
  111. self.player.playerDidToEnd = ^(id _Nonnull asset) {
  112. NSLog(@"结束");
  113. [weakSelf.player.currentPlayerManager replay];
  114. };
  115. /*
  116. /// 封面信息
  117. [self.controlView showCoverViewWithUrl:_itemLayout.data.video_thumb];
  118. CGSize videoSize = CGSizeMake(_itemLayout.data.width, _itemLayout.data.height);
  119. self.player.currentPlayerManager.presentationSize = videoSize;
  120. */
  121. }
  122. - (YBGoodPlayerCtrView *)controlView {
  123. if (!_controlView) {
  124. _controlView = [YBGoodPlayerCtrView new];
  125. }
  126. return _controlView;
  127. }
  128. @end