IJKMediaPlayback.h 8.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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. @property(nonatomic, readonly) UIView *view;
  67. @property(nonatomic) NSTimeInterval currentPlaybackTime;
  68. @property(nonatomic, readonly) NSTimeInterval duration;
  69. @property(nonatomic, readonly) NSTimeInterval playableDuration;
  70. @property(nonatomic, readonly) NSInteger bufferingProgress;
  71. @property(nonatomic, readonly) BOOL isPreparedToPlay;
  72. @property(nonatomic, readonly) IJKMPMoviePlaybackState playbackState;
  73. @property(nonatomic, readonly) IJKMPMovieLoadState loadState;
  74. @property(nonatomic, readonly) int64_t numberOfBytesTransferred;
  75. @property(nonatomic, readonly) CGSize naturalSize;
  76. @property(nonatomic) IJKMPMovieScalingMode scalingMode;
  77. @property(nonatomic) BOOL shouldAutoplay;
  78. @property (nonatomic) BOOL allowsMediaAirPlay;
  79. @property (nonatomic) BOOL isDanmakuMediaAirPlay;
  80. @property (nonatomic, readonly) BOOL airPlayMediaActive;
  81. @property (nonatomic) float playbackRate;
  82. @property (nonatomic) float playbackVolume;
  83. - (UIImage *)thumbnailImageAtCurrentTime;
  84. #pragma mark Notifications
  85. #ifdef __cplusplus
  86. #define IJK_EXTERN extern "C" __attribute__((visibility ("default")))
  87. #else
  88. #define IJK_EXTERN extern __attribute__((visibility ("default")))
  89. #endif
  90. // -----------------------------------------------------------------------------
  91. // MPMediaPlayback.h
  92. // Posted when the prepared state changes of an object conforming to the MPMediaPlayback protocol changes.
  93. // This supersedes MPMoviePlayerContentPreloadDidFinishNotification.
  94. IJK_EXTERN NSString *const IJKMPMediaPlaybackIsPreparedToPlayDidChangeNotification;
  95. // -----------------------------------------------------------------------------
  96. // MPMoviePlayerController.h
  97. // Movie Player Notifications
  98. // Posted when the scaling mode changes.
  99. IJK_EXTERN NSString* const IJKMPMoviePlayerScalingModeDidChangeNotification;
  100. // Posted when movie playback ends or a user exits playback.
  101. IJK_EXTERN NSString* const IJKMPMoviePlayerPlaybackDidFinishNotification;
  102. IJK_EXTERN NSString* const IJKMPMoviePlayerPlaybackDidFinishReasonUserInfoKey; // NSNumber (IJKMPMovieFinishReason)
  103. // Posted when the playback state changes, either programatically or by the user.
  104. IJK_EXTERN NSString* const IJKMPMoviePlayerPlaybackStateDidChangeNotification;
  105. // Posted when the network load state changes.
  106. IJK_EXTERN NSString* const IJKMPMoviePlayerLoadStateDidChangeNotification;
  107. // Posted when the movie player begins or ends playing video via AirPlay.
  108. IJK_EXTERN NSString* const IJKMPMoviePlayerIsAirPlayVideoActiveDidChangeNotification;
  109. // -----------------------------------------------------------------------------
  110. // Movie Property Notifications
  111. // Calling -prepareToPlay on the movie player will begin determining movie properties asynchronously.
  112. // These notifications are posted when the associated movie property becomes available.
  113. IJK_EXTERN NSString* const IJKMPMovieNaturalSizeAvailableNotification;
  114. // -----------------------------------------------------------------------------
  115. // Extend Notifications
  116. IJK_EXTERN NSString *const IJKMPMoviePlayerVideoDecoderOpenNotification;
  117. IJK_EXTERN NSString *const IJKMPMoviePlayerFirstVideoFrameRenderedNotification;
  118. IJK_EXTERN NSString *const IJKMPMoviePlayerFirstAudioFrameRenderedNotification;
  119. IJK_EXTERN NSString *const IJKMPMoviePlayerFirstAudioFrameDecodedNotification;
  120. IJK_EXTERN NSString *const IJKMPMoviePlayerFirstVideoFrameDecodedNotification;
  121. IJK_EXTERN NSString *const IJKMPMoviePlayerOpenInputNotification;
  122. IJK_EXTERN NSString *const IJKMPMoviePlayerFindStreamInfoNotification;
  123. IJK_EXTERN NSString *const IJKMPMoviePlayerComponentOpenNotification;
  124. IJK_EXTERN NSString *const IJKMPMoviePlayerDidSeekCompleteNotification;
  125. IJK_EXTERN NSString *const IJKMPMoviePlayerDidSeekCompleteTargetKey;
  126. IJK_EXTERN NSString *const IJKMPMoviePlayerDidSeekCompleteErrorKey;
  127. IJK_EXTERN NSString *const IJKMPMoviePlayerDidAccurateSeekCompleteCurPos;
  128. IJK_EXTERN NSString *const IJKMPMoviePlayerAccurateSeekCompleteNotification;
  129. @end
  130. #pragma mark IJKMediaUrlOpenDelegate
  131. // Must equal to the defination in ijkavformat/ijkavformat.h
  132. typedef NS_ENUM(NSInteger, IJKMediaEvent) {
  133. // Notify Events
  134. IJKMediaEvent_WillHttpOpen = 1, // attr: url
  135. IJKMediaEvent_DidHttpOpen = 2, // attr: url, error, http_code
  136. IJKMediaEvent_WillHttpSeek = 3, // attr: url, offset
  137. IJKMediaEvent_DidHttpSeek = 4, // attr: url, offset, error, http_code
  138. // Control Message
  139. IJKMediaCtrl_WillTcpOpen = 0x20001, // IJKMediaUrlOpenData: no args
  140. IJKMediaCtrl_DidTcpOpen = 0x20002, // IJKMediaUrlOpenData: error, family, ip, port, fd
  141. IJKMediaCtrl_WillHttpOpen = 0x20003, // IJKMediaUrlOpenData: url, segmentIndex, retryCounter
  142. IJKMediaCtrl_WillLiveOpen = 0x20005, // IJKMediaUrlOpenData: url, retryCounter
  143. IJKMediaCtrl_WillConcatSegmentOpen = 0x20007, // IJKMediaUrlOpenData: url, segmentIndex, retryCounter
  144. };
  145. #define IJKMediaEventAttrKey_url @"url"
  146. #define IJKMediaEventAttrKey_host @"host"
  147. #define IJKMediaEventAttrKey_error @"error"
  148. #define IJKMediaEventAttrKey_time_of_event @"time_of_event"
  149. #define IJKMediaEventAttrKey_http_code @"http_code"
  150. #define IJKMediaEventAttrKey_offset @"offset"
  151. // event of IJKMediaUrlOpenEvent_xxx
  152. @interface IJKMediaUrlOpenData: NSObject
  153. - (id)initWithUrl:(NSString *)url
  154. event:(IJKMediaEvent)event
  155. segmentIndex:(int)segmentIndex
  156. retryCounter:(int)retryCounter;
  157. @property(nonatomic, readonly) IJKMediaEvent event;
  158. @property(nonatomic, readonly) int segmentIndex;
  159. @property(nonatomic, readonly) int retryCounter;
  160. @property(nonatomic, retain) NSString *url;
  161. @property(nonatomic, assign) int fd;
  162. @property(nonatomic, strong) NSString *msg;
  163. @property(nonatomic) int error; // set a negative value to indicate an error has occured.
  164. @property(nonatomic, getter=isHandled) BOOL handled; // auto set to YES if url changed
  165. @property(nonatomic, getter=isUrlChanged) BOOL urlChanged; // auto set to YES by url changed
  166. @end
  167. @protocol IJKMediaUrlOpenDelegate <NSObject>
  168. - (void)willOpenUrl:(IJKMediaUrlOpenData*) urlOpenData;
  169. @end
  170. @protocol IJKMediaNativeInvokeDelegate <NSObject>
  171. - (int)invoke:(IJKMediaEvent)event attributes:(NSDictionary *)attributes;
  172. @end