ZFPlayerMediaPlayback.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. //
  2. // ZFMediaPlayback.h
  3. // ZFPlayer
  4. //
  5. // Copyright (c) 2016年 任子丰 ( http://github.com/renzifeng )
  6. //
  7. // Permission is hereby granted, free of charge, to any person obtaining a copy
  8. // of this software and associated documentation files (the "Software"), to deal
  9. // in the Software without restriction, including without limitation the rights
  10. // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  11. // copies of the Software, and to permit persons to whom the Software is
  12. // furnished to do so, subject to the following conditions:
  13. //
  14. // The above copyright notice and this permission notice shall be included in
  15. // all copies or substantial portions of the Software.
  16. //
  17. // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  18. // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  19. // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  20. // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  21. // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  22. // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  23. // THE SOFTWARE.
  24. #import <Foundation/Foundation.h>
  25. #import "ZFPlayerView.h"
  26. NS_ASSUME_NONNULL_BEGIN
  27. typedef NS_ENUM(NSUInteger, ZFPlayerPlaybackState) {
  28. ZFPlayerPlayStateUnknown,
  29. ZFPlayerPlayStatePlaying,
  30. ZFPlayerPlayStatePaused,
  31. ZFPlayerPlayStatePlayFailed,
  32. ZFPlayerPlayStatePlayStopped
  33. };
  34. typedef NS_OPTIONS(NSUInteger, ZFPlayerLoadState) {
  35. ZFPlayerLoadStateUnknown = 0,
  36. ZFPlayerLoadStatePrepare = 1 << 0,
  37. ZFPlayerLoadStatePlayable = 1 << 1,
  38. ZFPlayerLoadStatePlaythroughOK = 1 << 2, // Playback will be automatically started.
  39. ZFPlayerLoadStateStalled = 1 << 3, // Playback will be automatically paused in this state, if started.
  40. };
  41. typedef NS_ENUM(NSInteger, ZFPlayerScalingMode) {
  42. ZFPlayerScalingModeNone, // No scaling.
  43. ZFPlayerScalingModeAspectFit, // Uniform scale until one dimension fits.
  44. ZFPlayerScalingModeAspectFill, // Uniform scale until the movie fills the visible bounds. One dimension may have clipped contents.
  45. ZFPlayerScalingModeFill // Non-uniform scale. Both render dimensions will exactly match the visible bounds.
  46. };
  47. @protocol ZFPlayerMediaPlayback <NSObject>
  48. @required
  49. /// The view must inherited `ZFPlayerView`,this view deals with some gesture conflicts.
  50. @property (nonatomic) ZFPlayerView *view;
  51. @optional
  52. /// The player volume.
  53. /// Only affects audio volume for the player instance and not for the device.
  54. /// You can change device volume or player volume as needed,change the player volume you can folllow the `ZFPlayerMediaPlayback` protocol.
  55. @property (nonatomic) float volume;
  56. /// The player muted.
  57. /// indicates whether or not audio output of the player is muted. Only affects audio muting for the player instance and not for the device.
  58. /// You can change device volume or player muted as needed,change the player muted you can folllow the `ZFPlayerMediaPlayback` protocol.
  59. @property (nonatomic, getter=isMuted) BOOL muted;
  60. /// Playback speed,0.5...2
  61. @property (nonatomic) float rate;
  62. /// The player current play time.
  63. @property (nonatomic, readonly) NSTimeInterval currentTime;
  64. /// The player total time.
  65. @property (nonatomic, readonly) NSTimeInterval totalTime;
  66. /// The player buffer time.
  67. @property (nonatomic, readonly) NSTimeInterval bufferTime;
  68. /// The player seek time.
  69. @property (nonatomic) NSTimeInterval seekTime;
  70. /// The player play state,playing or not playing.
  71. @property (nonatomic, readonly) BOOL isPlaying;
  72. /// Determines how the content scales to fit the view. Defaults to ZFPlayerScalingModeNone.
  73. @property (nonatomic) ZFPlayerScalingMode scalingMode;
  74. /**
  75. @abstract Check whether video preparation is complete.
  76. @discussion isPreparedToPlay processing logic
  77. * If isPreparedToPlay is true, you can call [ZFPlayerMediaPlayback play] API start playing;
  78. * If isPreparedToPlay to false, direct call [ZFPlayerMediaPlayback play], in the play the internal automatic call [ZFPlayerMediaPlayback prepareToPlay] API.
  79. * Returns true if prepared for playback.
  80. */
  81. @property (nonatomic, readonly) BOOL isPreparedToPlay;
  82. /// The player should auto player, default is YES.
  83. @property (nonatomic) BOOL shouldAutoPlay;
  84. /// The play asset URL.
  85. @property (nonatomic) NSURL *assetURL;
  86. /// The video size.
  87. @property (nonatomic, readonly) CGSize presentationSize;
  88. /// The playback state.
  89. @property (nonatomic, readonly) ZFPlayerPlaybackState playState;
  90. /// The player load state.
  91. @property (nonatomic, readonly) ZFPlayerLoadState loadState;
  92. ///------------------------------------
  93. /// If you don't appoint the controlView, you can called the following blocks.
  94. /// If you appoint the controlView, The following block cannot be called outside, only for `ZFPlayerController` calls.
  95. ///------------------------------------
  96. /// The block invoked when the player is Prepare to play.
  97. @property (nonatomic, copy, nullable) void(^playerPrepareToPlay)(id<ZFPlayerMediaPlayback> asset, NSURL *assetURL);
  98. /// The block invoked when the player is Ready to play.
  99. @property (nonatomic, copy, nullable) void(^playerReadyToPlay)(id<ZFPlayerMediaPlayback> asset, NSURL *assetURL);
  100. /// The block invoked when the player play progress changed.
  101. @property (nonatomic, copy, nullable) void(^playerPlayTimeChanged)(id<ZFPlayerMediaPlayback> asset, NSTimeInterval currentTime, NSTimeInterval duration);
  102. /// The block invoked when the player play buffer changed.
  103. @property (nonatomic, copy, nullable) void(^playerBufferTimeChanged)(id<ZFPlayerMediaPlayback> asset, NSTimeInterval bufferTime);
  104. /// The block invoked when the player playback state changed.
  105. @property (nonatomic, copy, nullable) void(^playerPlayStateChanged)(id<ZFPlayerMediaPlayback> asset, ZFPlayerPlaybackState playState);
  106. /// The block invoked when the player load state changed.
  107. @property (nonatomic, copy, nullable) void(^playerLoadStateChanged)(id<ZFPlayerMediaPlayback> asset, ZFPlayerLoadState loadState);
  108. /// The block invoked when the player play failed.
  109. @property (nonatomic, copy, nullable) void(^playerPlayFailed)(id<ZFPlayerMediaPlayback> asset, id error);
  110. /// The block invoked when the player play end.
  111. @property (nonatomic, copy, nullable) void(^playerDidToEnd)(id<ZFPlayerMediaPlayback> asset);
  112. // The block invoked when video size changed.
  113. @property (nonatomic, copy, nullable) void(^presentationSizeChanged)(id<ZFPlayerMediaPlayback> asset, CGSize size);
  114. ///------------------------------------
  115. /// end
  116. ///------------------------------------
  117. /// Prepares the current queue for playback, interrupting any active (non-mixible) audio sessions.
  118. - (void)prepareToPlay;
  119. /// Reload player.
  120. - (void)reloadPlayer;
  121. /// Play playback.
  122. - (void)play;
  123. /// Pauses playback.
  124. - (void)pause;
  125. /// Replay playback.
  126. - (void)replay;
  127. /// Stop playback.
  128. - (void)stop;
  129. /// Video UIImage at the current time.
  130. - (UIImage *)thumbnailImageAtCurrentTime;
  131. /// Use this method to seek to a specified time for the current player and to be notified when the seek operation is complete.
  132. - (void)seekToTime:(NSTimeInterval)time completionHandler:(void (^ __nullable)(BOOL finished))completionHandler;
  133. @end
  134. NS_ASSUME_NONNULL_END