MPPlayerController.h 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129
  1. #import <Foundation/Foundation.h>
  2. #import <ZFPlayer.h>
  3. #import "MPPlayableProtocol.h"
  4. NS_ASSUME_NONNULL_BEGIN
  5. @interface MPPlayerController : NSObject
  6. @property (nonatomic, strong) ZFPlayerController *player;
  7. // 预加载上几条
  8. @property (nonatomic, assign) NSUInteger preLoadNum;
  9. /// 预加载下几条
  10. @property (nonatomic, assign) NSUInteger nextLoadNum;
  11. /// 预加载的的百分比,默认10%
  12. @property (nonatomic, assign) double preloadPrecent;
  13. /// 设置playableAssets后,马上预加载的条数
  14. @property (nonatomic, assign) NSUInteger initPreloadNum;
  15. /// The indexPath is playing.
  16. @property (nonatomic, readonly, nullable) NSIndexPath *playingIndexPath;
  17. /// The current player controller is disappear, not dealloc
  18. @property (nonatomic, getter=isViewControllerDisappear) BOOL viewControllerDisappear;
  19. @property (nonatomic, readonly) UIView *containerView;
  20. /// 可播放的视频的模型数组,若是混合区域,模型需要实现XSTPlayable
  21. /// set之后,先预加载几个
  22. @property (nonatomic, copy) NSArray<id<XSTPlayable>> *playableArray;
  23. /// 当前正在播放的 MPPlayable 资源
  24. @property (nonatomic, strong, readonly) id<XSTPlayable> currentPlayable;
  25. /// The currentPlayerManager must conform `ZFPlayerMediaPlayback` protocol.
  26. @property (nonatomic, strong) id<ZFPlayerMediaPlayback> currentPlayerManager;
  27. /// The custom controlView must conform `ZFPlayerMediaControl` protocol.
  28. @property (nonatomic, strong) UIView<ZFPlayerMediaControl> *controlView;
  29. /// 保存player在信息流时,应该显示的scalingMode
  30. @property (nonatomic, assign) ZFPlayerScalingMode videoFlowScalingMode;
  31. @property (nonatomic) CGFloat playerDisapperaPercent;
  32. @property (nonatomic) CGFloat playerApperaPercent;
  33. @property (nonatomic, getter=isWWANAutoPlay) BOOL WWANAutoPlay;
  34. @property (nonatomic, assign) BOOL isPlaying;
  35. // MARK: - Block
  36. /// 准备播放的block
  37. @property (nonatomic, copy, nullable) void(^playerReadyToPlay)(id<ZFPlayerMediaPlayback> asset, NSURL *assetURL);
  38. /// 播放进度的block
  39. @property (nonatomic, copy, nullable) void(^playerPlayTimeChanged)(id<ZFPlayerMediaPlayback> asset, NSTimeInterval currentTime, NSTimeInterval duration);
  40. /// 播放缓存时间的block
  41. @property (nonatomic, copy, nullable) void(^playerBufferTimeChanged)(id<ZFPlayerMediaPlayback> asset, NSTimeInterval bufferTime);
  42. /// 播放失败回调
  43. @property (nonatomic, copy, nullable) void(^playerPlayFailed)(id<ZFPlayerMediaPlayback> asset, id error);
  44. /// 播放到结尾的回调
  45. @property (nonatomic, copy, nullable) void(^playerDidToEnd)(id<ZFPlayerMediaPlayback> asset);
  46. // 播放器size变化的回调
  47. @property (nonatomic, copy, nullable) void(^presentationSizeChanged)(id<ZFPlayerMediaPlayback> asset, CGSize size);
  48. /// The block invoked when the player playback state changed.
  49. @property (nonatomic, copy, nullable) void(^playerPlayStateChanged)(id<ZFPlayerMediaPlayback> asset, ZFPlayerPlaybackState playState);
  50. /// The block invoked when the player load state changed.
  51. @property (nonatomic, copy, nullable) void(^playerLoadStateChanged)(id<ZFPlayerMediaPlayback> asset, ZFPlayerLoadState loadState);
  52. @property (nonatomic, copy, nullable) void(^zf_playerDisappearingInScrollView)(NSIndexPath *indexPath, CGFloat playerDisapperaPercent);
  53. @property (nonatomic, copy, nullable) void(^zf_playerDidDisappearInScrollView)(NSIndexPath *indexPath);
  54. // MARK: - Init
  55. /**
  56. 创建播放单个视频的PlayerController
  57. @param containerView 指定显示视频的容器
  58. @return MPPlayerController实例
  59. */
  60. + (instancetype)playrWithContainerView:(UIView *)containerView;
  61. /**
  62. 创建播放单个视频的PlayerController
  63. @param containerView 指定显示视频的容器
  64. @return MPPlayerController实例
  65. */
  66. - (instancetype)initWithContainerView:(UIView *)containerView;
  67. /**
  68. 在UITableView或UICollectionView中使用的PlayerController
  69. @param scrollView UITableView或UICollectionView
  70. @param containerViewTag 指定显示视频的容器tag,cell的子视图的tag
  71. @return PlayerController实例
  72. */
  73. + (instancetype)playerWithScrollView:(UIScrollView *)scrollView containerViewTag:(NSInteger)containerViewTag;
  74. /**
  75. 在UITableView或UICollectionView中使用的PlayerController
  76. @param scrollView UITableView或UICollectionView
  77. @param containerViewTag 指定显示视频的容器tag,cell的子视图的tag
  78. @return PlayerController实例
  79. */
  80. - (instancetype)initWithScrollView:(UIScrollView *)scrollView containerViewTag:(NSInteger)containerViewTag;
  81. // MARK: - Method
  82. /// 移除player,移除其他通知
  83. - (void)stop;
  84. /// 停止播放播放的Cell
  85. - (void)stopCurrentPlayingCell;
  86. /// 播放对应的indexPath,传入resouce
  87. - (void)playTheIndexPath:(NSIndexPath *)indexPath playable: (id<XSTPlayable>)playable;
  88. /// 播放指定的url
  89. - (void)playWithPlayable: (id<XSTPlayable>)playable;
  90. /// 设置player显示,消失的百分比,用于判断自动播放和暂停
  91. - (void)setDisapperaPercent: (CGFloat)disappearPercent appearPercent: (CGFloat)appearPercent;
  92. /// 横屏显示
  93. - (void)enterLandscapeFullScreen:(UIInterfaceOrientation)orientation animated:(BOOL)animated;
  94. /// 退出全屏
  95. - (void)exitFullScreen: (BOOL)isAnimated;
  96. /// Add Player到Cell上
  97. - (void)updateScrollViewPlayerToCell;
  98. /// 更新Playerc的容器
  99. - (void)updateNoramlPlayerWithContainerView:(UIView *)containerView;
  100. @end
  101. NS_ASSUME_NONNULL_END