IJKMediaPlayback.h 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232
  1. /*
  2. * IJKMediaPlayback.h
  3. *
  4. * Copyright (c) 2013 Bilibili
  5. * Copyright (c) 2013 Zhang Rui <bbcallen@gmail.com>
  6. *
  7. * This file is part of ijkPlayer.
  8. *
  9. * ijkPlayer is free software; you can redistribute it and/or
  10. * modify it under the terms of the GNU Lesser General Public
  11. * License as published by the Free Software Foundation; either
  12. * version 2.1 of the License, or (at your option) any later version.
  13. *
  14. * ijkPlayer is distributed in the hope that it will be useful,
  15. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  16. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  17. * Lesser General Public License for more details.
  18. *
  19. * You should have received a copy of the GNU Lesser General Public
  20. * License along with ijkPlayer; if not, write to the Free Software
  21. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  22. */
  23. #import <Foundation/Foundation.h>
  24. #import <UIKit/UIKit.h>
  25. typedef NS_ENUM(NSInteger, IJKMPMovieScalingMode) {
  26. IJKMPMovieScalingModeNone, // No scaling
  27. IJKMPMovieScalingModeAspectFit, // Uniform scale until one dimension fits
  28. IJKMPMovieScalingModeAspectFill, // Uniform scale until the movie fills the visible bounds. One dimension may have clipped contents
  29. IJKMPMovieScalingModeFill // Non-uniform scale. Both render dimensions will exactly match the visible bounds
  30. };
  31. typedef NS_ENUM(NSInteger, IJKMPMoviePlaybackState) {
  32. IJKMPMoviePlaybackStateStopped,
  33. IJKMPMoviePlaybackStatePlaying,
  34. IJKMPMoviePlaybackStatePaused,
  35. IJKMPMoviePlaybackStateInterrupted,
  36. IJKMPMoviePlaybackStateSeekingForward,
  37. IJKMPMoviePlaybackStateSeekingBackward
  38. };
  39. typedef NS_OPTIONS(NSUInteger, IJKMPMovieLoadState) {
  40. IJKMPMovieLoadStateUnknown = 0,
  41. IJKMPMovieLoadStatePlayable = 1 << 0,
  42. IJKMPMovieLoadStatePlaythroughOK = 1 << 1, // Playback will be automatically started in this state when shouldAutoplay is YES
  43. IJKMPMovieLoadStateStalled = 1 << 2, // Playback will be automatically paused in this state, if started
  44. };
  45. typedef NS_ENUM(NSInteger, IJKMPMovieFinishReason) {
  46. IJKMPMovieFinishReasonPlaybackEnded,
  47. IJKMPMovieFinishReasonPlaybackError,
  48. IJKMPMovieFinishReasonUserExited
  49. };
  50. // -----------------------------------------------------------------------------
  51. // Thumbnails
  52. typedef NS_ENUM(NSInteger, IJKMPMovieTimeOption) {
  53. IJKMPMovieTimeOptionNearestKeyFrame,
  54. IJKMPMovieTimeOptionExact
  55. };
  56. @protocol IJKMediaPlayback;
  57. #pragma mark IJKMediaPlayback
  58. @protocol IJKMediaPlayback <NSObject>
  59. - (void)prepareToPlay;
  60. - (void)play;
  61. - (void)pause;
  62. - (void)stop;
  63. - (BOOL)isPlaying;
  64. - (void)shutdown;
  65. - (void)setPauseInBackground:(BOOL)pause;
  66. #pragma mark for flutter
  67. - (CVPixelBufferRef)framePixelbuffer;
  68. - (void)framePixelbufferLock;
  69. - (void)framePixelbufferUnlock;
  70. @property(nonatomic, readonly) UIView *view;
  71. @property(nonatomic) NSTimeInterval currentPlaybackTime;
  72. @property(nonatomic, readonly) NSTimeInterval duration;
  73. @property(nonatomic, readonly) NSTimeInterval playableDuration;
  74. @property(nonatomic, readonly) NSInteger bufferingProgress;
  75. @property(nonatomic, readonly) BOOL isPreparedToPlay;
  76. @property(nonatomic, readonly) IJKMPMoviePlaybackState playbackState;
  77. @property(nonatomic, readonly) IJKMPMovieLoadState loadState;
  78. @property(nonatomic, readonly) int isSeekBuffering;
  79. @property(nonatomic, readonly) int isAudioSync;
  80. @property(nonatomic, readonly) int isVideoSync;
  81. @property(nonatomic, readonly) int64_t numberOfBytesTransferred;
  82. @property(nonatomic, readonly) CGSize naturalSize;
  83. @property(nonatomic) IJKMPMovieScalingMode scalingMode;
  84. @property(nonatomic) BOOL shouldAutoplay;
  85. @property (nonatomic) BOOL allowsMediaAirPlay;
  86. @property (nonatomic) BOOL isDanmakuMediaAirPlay;
  87. @property (nonatomic, readonly) BOOL airPlayMediaActive;
  88. @property (nonatomic) float playbackRate;
  89. @property (nonatomic) float playbackVolume;
  90. - (UIImage *)thumbnailImageAtCurrentTime;
  91. #pragma mark Notifications
  92. #ifdef __cplusplus
  93. #define IJK_EXTERN extern "C" __attribute__((visibility ("default")))
  94. #else
  95. #define IJK_EXTERN extern __attribute__((visibility ("default")))
  96. #endif
  97. // -----------------------------------------------------------------------------
  98. // MPMediaPlayback.h
  99. // Posted when the prepared state changes of an object conforming to the MPMediaPlayback protocol changes.
  100. // This supersedes MPMoviePlayerContentPreloadDidFinishNotification.
  101. IJK_EXTERN NSString *const IJKMPMediaPlaybackIsPreparedToPlayDidChangeNotification;
  102. // -----------------------------------------------------------------------------
  103. // MPMoviePlayerController.h
  104. // Movie Player Notifications
  105. // Posted when the scaling mode changes.
  106. IJK_EXTERN NSString* const IJKMPMoviePlayerScalingModeDidChangeNotification;
  107. // Posted when movie playback ends or a user exits playback.
  108. IJK_EXTERN NSString* const IJKMPMoviePlayerPlaybackDidFinishNotification;
  109. IJK_EXTERN NSString* const IJKMPMoviePlayerPlaybackDidFinishReasonUserInfoKey; // NSNumber (IJKMPMovieFinishReason)
  110. // Posted when the playback state changes, either programatically or by the user.
  111. IJK_EXTERN NSString* const IJKMPMoviePlayerPlaybackStateDidChangeNotification;
  112. // Posted when the network load state changes.
  113. IJK_EXTERN NSString* const IJKMPMoviePlayerLoadStateDidChangeNotification;
  114. // Posted when the movie player begins or ends playing video via AirPlay.
  115. IJK_EXTERN NSString* const IJKMPMoviePlayerIsAirPlayVideoActiveDidChangeNotification;
  116. // -----------------------------------------------------------------------------
  117. // Movie Property Notifications
  118. // Calling -prepareToPlay on the movie player will begin determining movie properties asynchronously.
  119. // These notifications are posted when the associated movie property becomes available.
  120. IJK_EXTERN NSString* const IJKMPMovieNaturalSizeAvailableNotification;
  121. // -----------------------------------------------------------------------------
  122. // Extend Notifications
  123. IJK_EXTERN NSString *const IJKMPMoviePlayerVideoDecoderOpenNotification;
  124. IJK_EXTERN NSString *const IJKMPMoviePlayerFirstVideoFrameRenderedNotification;
  125. IJK_EXTERN NSString *const IJKMPMoviePlayerFirstAudioFrameRenderedNotification;
  126. IJK_EXTERN NSString *const IJKMPMoviePlayerFirstAudioFrameDecodedNotification;
  127. IJK_EXTERN NSString *const IJKMPMoviePlayerFirstVideoFrameDecodedNotification;
  128. IJK_EXTERN NSString *const IJKMPMoviePlayerOpenInputNotification;
  129. IJK_EXTERN NSString *const IJKMPMoviePlayerFindStreamInfoNotification;
  130. IJK_EXTERN NSString *const IJKMPMoviePlayerComponentOpenNotification;
  131. IJK_EXTERN NSString *const IJKMPMoviePlayerDidSeekCompleteNotification;
  132. IJK_EXTERN NSString *const IJKMPMoviePlayerDidSeekCompleteTargetKey;
  133. IJK_EXTERN NSString *const IJKMPMoviePlayerDidSeekCompleteErrorKey;
  134. IJK_EXTERN NSString *const IJKMPMoviePlayerDidAccurateSeekCompleteCurPos;
  135. IJK_EXTERN NSString *const IJKMPMoviePlayerAccurateSeekCompleteNotification;
  136. IJK_EXTERN NSString *const IJKMPMoviePlayerSeekAudioStartNotification;
  137. IJK_EXTERN NSString *const IJKMPMoviePlayerSeekVideoStartNotification;
  138. @end
  139. #pragma mark IJKMediaUrlOpenDelegate
  140. // Must equal to the defination in ijkavformat/ijkavformat.h
  141. typedef NS_ENUM(NSInteger, IJKMediaEvent) {
  142. // Notify Events
  143. IJKMediaEvent_WillHttpOpen = 1, // attr: url
  144. IJKMediaEvent_DidHttpOpen = 2, // attr: url, error, http_code
  145. IJKMediaEvent_WillHttpSeek = 3, // attr: url, offset
  146. IJKMediaEvent_DidHttpSeek = 4, // attr: url, offset, error, http_code
  147. // Control Message
  148. IJKMediaCtrl_WillTcpOpen = 0x20001, // IJKMediaUrlOpenData: no args
  149. IJKMediaCtrl_DidTcpOpen = 0x20002, // IJKMediaUrlOpenData: error, family, ip, port, fd
  150. IJKMediaCtrl_WillHttpOpen = 0x20003, // IJKMediaUrlOpenData: url, segmentIndex, retryCounter
  151. IJKMediaCtrl_WillLiveOpen = 0x20005, // IJKMediaUrlOpenData: url, retryCounter
  152. IJKMediaCtrl_WillConcatSegmentOpen = 0x20007, // IJKMediaUrlOpenData: url, segmentIndex, retryCounter
  153. };
  154. #define IJKMediaEventAttrKey_url @"url"
  155. #define IJKMediaEventAttrKey_host @"host"
  156. #define IJKMediaEventAttrKey_error @"error"
  157. #define IJKMediaEventAttrKey_time_of_event @"time_of_event"
  158. #define IJKMediaEventAttrKey_http_code @"http_code"
  159. #define IJKMediaEventAttrKey_offset @"offset"
  160. #define IJKMediaEventAttrKey_file_size @"file_size"
  161. // event of IJKMediaUrlOpenEvent_xxx
  162. @interface IJKMediaUrlOpenData: NSObject
  163. - (id)initWithUrl:(NSString *)url
  164. event:(IJKMediaEvent)event
  165. segmentIndex:(int)segmentIndex
  166. retryCounter:(int)retryCounter;
  167. @property(nonatomic, readonly) IJKMediaEvent event;
  168. @property(nonatomic, readonly) int segmentIndex;
  169. @property(nonatomic, readonly) int retryCounter;
  170. @property(nonatomic, retain) NSString *url;
  171. @property(nonatomic, assign) int fd;
  172. @property(nonatomic, strong) NSString *msg;
  173. @property(nonatomic) int error; // set a negative value to indicate an error has occured.
  174. @property(nonatomic, getter=isHandled) BOOL handled; // auto set to YES if url changed
  175. @property(nonatomic, getter=isUrlChanged) BOOL urlChanged; // auto set to YES by url changed
  176. @end
  177. @protocol IJKMediaUrlOpenDelegate <NSObject>
  178. - (void)willOpenUrl:(IJKMediaUrlOpenData*) urlOpenData;
  179. @end
  180. @protocol IJKMediaNativeInvokeDelegate <NSObject>
  181. - (int)invoke:(IJKMediaEvent)event attributes:(NSDictionary *)attributes;
  182. @end