Commit 076d18cdf0be287d7ae6bb36f66db8508ebd2050

Authored by zhangxiaowen
1 parent 08b73c03

no message

CNLivePlayer/Classes/Database/CNLivePlayerDBModel.h
@@ -11,9 +11,10 @@ @@ -11,9 +11,10 @@
11 NS_ASSUME_NONNULL_BEGIN 11 NS_ASSUME_NONNULL_BEGIN
12 12
13 @interface CNLivePlayerDBModel : NSObject 13 @interface CNLivePlayerDBModel : NSObject
14 - 14 +//contentId:rate
15 @property (nullable, nonatomic, copy) NSString *contentId; 15 @property (nullable, nonatomic, copy) NSString *contentId;
16 @property (nullable, nonatomic, copy) NSString *url; 16 @property (nullable, nonatomic, copy) NSString *url;
  17 +@property (nullable, nonatomic, copy) NSString *proxyUrl;
17 @property (nonatomic, assign) BOOL finish; 18 @property (nonatomic, assign) BOOL finish;
18 - (CNLivePlayerDBModel *)initWithContenId:(NSString *)contentId url:(NSString *)url; 19 - (CNLivePlayerDBModel *)initWithContenId:(NSString *)contentId url:(NSString *)url;
19 20
CNLivePlayer/Classes/Database/CNLivePlayerDBTool.m
@@ -61,7 +61,7 @@ @@ -61,7 +61,7 @@
61 #pragma mark - 自定义操作 61 #pragma mark - 自定义操作
62 - (void)createTable{ 62 - (void)createTable{
63 [self openDB:^(int result, FMDatabase *db) { 63 [self openDB:^(int result, FMDatabase *db) {
64 - NSString * sql = @"CREATE TABLE DATATABLE (contentId varchar, url varchar, finish int)"; 64 + NSString * sql = @"CREATE TABLE DATATABLE (contentId varchar, url varchar, finish bit)";
65 BOOL res = [db executeUpdate:sql]; 65 BOOL res = [db executeUpdate:sql];
66 if (!res) { 66 if (!res) {
67 NSLog(@"建表失败"); 67 NSLog(@"建表失败");
@@ -111,7 +111,7 @@ @@ -111,7 +111,7 @@
111 - (BOOL)updateInTable:(NSString *)contentId{ 111 - (BOOL)updateInTable:(NSString *)contentId{
112 __block BOOL isResult = NO; 112 __block BOOL isResult = NO;
113 [self openDB:^(int result, FMDatabase *db) { 113 [self openDB:^(int result, FMDatabase *db) {
114 - NSString * check = [NSString stringWithFormat:@"UPDATE DATATABLE SET finish = true where contentId = '%@'",contentId]; 114 + NSString * check = [NSString stringWithFormat:@"UPDATE DATATABLE SET finish = 1 where contentId = '%@'",contentId];
115 isResult = [db executeUpdate:check]; 115 isResult = [db executeUpdate:check];
116 }]; 116 }];
117 return isResult; 117 return isResult;
CNLivePlayer/Classes/Player/CNLivePlayer.h
@@ -161,6 +161,79 @@ typedef void(^AuthFailureBlock)(NSDictionary *errorInfo); @@ -161,6 +161,79 @@ typedef void(^AuthFailureBlock)(NSDictionary *errorInfo);
161 */ 161 */
162 @property(nonatomic, assign) NSTimeInterval currentPlaybackTime; 162 @property(nonatomic, assign) NSTimeInterval currentPlaybackTime;
163 163
  164 +/**
  165 + * 当前视频总时长
  166 + * 视频总时长,单位是秒。
  167 + * 如果是直播视频源,总时长为0.
  168 + * 如果该信息未知,总时长默认为0.
  169 + */
  170 +@property (nonatomic, readonly) NSTimeInterval duration;
  171 +
  172 +/**
  173 + @abstract 当前视频宽高
  174 + @discussion 获取信息
  175 +
  176 + * 监听MPMovieNaturalSizeAvailableNotification
  177 + * 播放过程中,宽高信息可能会产生更改
  178 +
  179 + @since Available in KSYMoviePlayerController 1.0 and later.
  180 + */
  181 +@property (nonatomic, readonly) CGSize naturalSize;
  182 +
  183 +/**
  184 + @abstract 当前视频自带旋转(逆时针)角度
  185 + @discussion rotateDegress 是人为旋转角度,naturalRotate是文件meta信息中自带的旋转角度
  186 + @warning 该方法由金山云引入,不是原生系统接口
  187 + @since Available in KSYMoviePlayerController 2.2.0 and later.
  188 + */
  189 +@property (nonatomic, readonly) NSInteger naturalRotate;
  190 +
  191 +/**
  192 + @abstract 当前播放器的播放状态(只读)。
  193 + @discussion 可以通过该属性获取视频播放情况:
  194 +
  195 + <pre><code>
  196 + typedef NS_ENUM(NSInteger, MPMoviePlaybackState) {
  197 + MPMoviePlaybackStateStopped, // 播放停止
  198 + MPMoviePlaybackStatePlaying, // 正在播放
  199 + MPMoviePlaybackStatePaused, // 播放暂停
  200 + MPMoviePlaybackStateInterrupted, // 播放被打断
  201 + MPMoviePlaybackStateSeekingForward, // 向前seeking中
  202 + MPMoviePlaybackStateSeekingBackward // 向后seeking中
  203 + } NS_DEPRECATED_IOS(3_2, 9_0);
  204 + </code></pre>
  205 + @discussion 通知:
  206 +
  207 + * MPMoviePlayerPlaybackDidFinishNotification,当播放完成时提供通知
  208 + * MPMoviePlayerPlaybackStateDidChangeNotification,当播放状态变化时提供通知
  209 +
  210 + @since Available in KSYMoviePlayerController 1.0 and later.
  211 + */
  212 +// Returns the current playback state of the movie player.
  213 +@property (nonatomic, readonly) MPMoviePlaybackState playbackState;
  214 +
  215 +
  216 +/**
  217 + @abstract 当前网络加载情况
  218 + @discussion 可以通过该属性获取视频加载情况:
  219 +
  220 + <pre><code>
  221 + typedef NS_OPTIONS(NSUInteger, MPMovieLoadState) {
  222 + MPMovieLoadStateUnknown = 0, // 加载情况未知
  223 + MPMovieLoadStatePlayable = 1 << 0, // 加载完成,可以播放
  224 + MPMovieLoadStatePlaythroughOK = 1 << 1, // 加载完成,如果shouldAutoplay为YES,将自动开始播放
  225 + MPMovieLoadStateStalled = 1 << 2, // 如果视频正在加载中
  226 + } NS_DEPRECATED_IOS(3_2, 9_0);
  227 + </code></pre>
  228 + @discussion 通知:
  229 +
  230 + * MPMoviePlayerLoadStateDidChangeNotification,当加载状态变化时提供通知
  231 +
  232 + @since Available in KSYMoviePlayerController 1.0 and later.
  233 + */
  234 +// Returns the network load state of the movie player.
  235 +@property (nonatomic, readonly) MPMovieLoadState loadState;
  236 +
164 #pragma mark - 方法 237 #pragma mark - 方法
165 /* 238 /*
166 * 获取主播状态(离开/已结束) 239 * 获取主播状态(离开/已结束)
@@ -218,6 +291,22 @@ typedef void(^AuthFailureBlock)(NSDictionary *errorInfo); @@ -218,6 +291,22 @@ typedef void(^AuthFailureBlock)(NSDictionary *errorInfo);
218 */ 291 */
219 - (UIImage *)thumbnailImageAtCurrentTime; 292 - (UIImage *)thumbnailImageAtCurrentTime;
220 293
  294 +/**
  295 + @abstract 重新启动拉流
  296 + @param aUrl 视频播放地址,该地址可以是本地地址或者服务器地址.如果为nil,则使用前一次播放地址
  297 + @discussion 调用场景如下:
  298 +
  299 + * 当播放器调用方发现卡顿时,可以主动调用
  300 + * 当估计出更优质的拉流ip时,可以主动调用
  301 + * 当发生WiFi/3G网络切换时,可以主动调用
  302 + * 当播放器回调体现播放完成时,可以主动调用
  303 + * 播放器SDK不会自动调用reload功能
  304 +
  305 + @warning 该方法由金山云引入,不是原生系统接口
  306 + @since Available in KSYMoviePlayerController 1.0 and later.
  307 + */
  308 +- (void)reload:(NSURL *)aUrl;
  309 +
221 @end 310 @end
222 311
223 NS_ASSUME_NONNULL_END 312 NS_ASSUME_NONNULL_END
CNLivePlayer/Classes/Player/CNLivePlayer.m
@@ -321,8 +321,8 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang @@ -321,8 +321,8 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang
321 if(!strongSelf.player){ 321 if(!strongSelf.player){
322 NSString *proxyUrl = [[CNLiveHTTPProxyService manager] getProxyUrl:strongSelf.videoUrl]; 322 NSString *proxyUrl = [[CNLiveHTTPProxyService manager] getProxyUrl:strongSelf.videoUrl];
323 strongSelf.player = [[KSYMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:PLAYER_OpenCache?proxyUrl:strongSelf.videoUrl]]; 323 strongSelf.player = [[KSYMoviePlayerController alloc] initWithContentURL:[NSURL URLWithString:PLAYER_OpenCache?proxyUrl:strongSelf.videoUrl]];
324 - [strongSelf.view addSubview:self.player.view];  
325 - strongSelf.player.view.frame = self.view.bounds; 324 + [strongSelf.view addSubview:strongSelf.player.view];
  325 + strongSelf.player.view.frame = strongSelf.view.bounds;
326 strongSelf.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight; 326 strongSelf.player.view.autoresizingMask = UIViewAutoresizingFlexibleWidth|UIViewAutoresizingFlexibleHeight;
327 strongSelf.player.shouldEnableKSYStatModule = NO; 327 strongSelf.player.shouldEnableKSYStatModule = NO;
328 if (PLAYER_TestEnvironment) { 328 if (PLAYER_TestEnvironment) {
@@ -379,7 +379,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang @@ -379,7 +379,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang
379 @"timestamp": [CNLivePlayerTools getTimestamp], 379 @"timestamp": [CNLivePlayerTools getTimestamp],
380 @"appId": PLAYER_AppID}; 380 @"appId": PLAYER_AppID};
381 381
382 - NSString *videoUrl = [CNLivePlayerTools encryptionSignWithUrl:authUrl parameter:parameter]; 382 + NSString *videoUrl = [CNLivePlayerTools encryptionSignWithUrl:AuthUrl parameter:parameter];
383 383
384 __weak typeof(self) weakSelf = self; 384 __weak typeof(self) weakSelf = self;
385 [[CNLivePlayerNetworkManager manager] authenticate:videoUrl success:^(NSURLResponse * _Nullable response, id _Nullable responseObject) { 385 [[CNLivePlayerNetworkManager manager] authenticate:videoUrl success:^(NSURLResponse * _Nullable response, id _Nullable responseObject) {
@@ -442,7 +442,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang @@ -442,7 +442,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang
442 @"sid": PLAYER_UserId, 442 @"sid": PLAYER_UserId,
443 @"uid": [CNLivePlayerTools getUidForTimestamp:stamp]}; 443 @"uid": [CNLivePlayerTools getUidForTimestamp:stamp]};
444 444
445 - NSString *videoUrl = [CNLivePlayerTools encryptionSignWithUrl:vodUrl parameter:parameter]; 445 + NSString *videoUrl = [CNLivePlayerTools encryptionSignWithUrl:VodUrl parameter:parameter];
446 446
447 __weak typeof(self) weakSelf = self; 447 __weak typeof(self) weakSelf = self;
448 [[CNLivePlayerNetworkManager manager] getVideoURL:videoUrl success:^(NSString * _Nullable videoURL, NSInteger code) { 448 [[CNLivePlayerNetworkManager manager] getVideoURL:videoUrl success:^(NSString * _Nullable videoURL, NSInteger code) {
@@ -499,7 +499,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang @@ -499,7 +499,7 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang
499 @"sid": PLAYER_UserId, 499 @"sid": PLAYER_UserId,
500 @"uid": [CNLivePlayerTools getUidForTimestamp:timestamp]}; 500 @"uid": [CNLivePlayerTools getUidForTimestamp:timestamp]};
501 501
502 - NSString *videoUrl = [CNLivePlayerTools encryptionSignWithUrl:liveUrl parameter:parameter]; 502 + NSString *videoUrl = [CNLivePlayerTools encryptionSignWithUrl:LiveUrl parameter:parameter];
503 503
504 // 拿到302跳转后的播放地址 504 // 拿到302跳转后的播放地址
505 NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:videoUrl]]; 505 NSMutableURLRequest *urlRequest = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:videoUrl]];
@@ -890,6 +890,90 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang @@ -890,6 +890,90 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang
890 890
891 } 891 }
892 892
  893 +/**
  894 + * 当前视频总时长
  895 + * 视频总时长,单位是秒。
  896 + * 如果是直播视频源,总时长为0.
  897 + * 如果该信息未知,总时长默认为0.
  898 + */
  899 +- (NSTimeInterval)duration{
  900 + return _player.duration;
  901 +
  902 +}
  903 +
  904 +/**
  905 + @abstract 当前视频宽高
  906 + @discussion 获取信息
  907 +
  908 + * 监听MPMovieNaturalSizeAvailableNotification
  909 + * 播放过程中,宽高信息可能会产生更改
  910 +
  911 + @since Available in KSYMoviePlayerController 1.0 and later.
  912 + */
  913 +- (CGSize)naturalSize{
  914 + return _player.naturalSize;
  915 +}
  916 +
  917 +/**
  918 + @abstract 当前视频自带旋转(逆时针)角度
  919 + @discussion rotateDegress 是人为旋转角度,naturalRotate是文件meta信息中自带的旋转角度
  920 + @warning 该方法由金山云引入,不是原生系统接口
  921 + @since Available in KSYMoviePlayerController 2.2.0 and later.
  922 + */
  923 +- (NSInteger)naturalRotate{
  924 + return _player.naturalRotate;
  925 +}
  926 +
  927 +/**
  928 + @abstract 当前播放器的播放状态(只读)。
  929 + @discussion 可以通过该属性获取视频播放情况:
  930 +
  931 + <pre><code>
  932 + typedef NS_ENUM(NSInteger, MPMoviePlaybackState) {
  933 + MPMoviePlaybackStateStopped, // 播放停止
  934 + MPMoviePlaybackStatePlaying, // 正在播放
  935 + MPMoviePlaybackStatePaused, // 播放暂停
  936 + MPMoviePlaybackStateInterrupted, // 播放被打断
  937 + MPMoviePlaybackStateSeekingForward, // 向前seeking中
  938 + MPMoviePlaybackStateSeekingBackward // 向后seeking中
  939 + } NS_DEPRECATED_IOS(3_2, 9_0);
  940 + </code></pre>
  941 + @discussion 通知:
  942 +
  943 + * MPMoviePlayerPlaybackDidFinishNotification,当播放完成时提供通知
  944 + * MPMoviePlayerPlaybackStateDidChangeNotification,当播放状态变化时提供通知
  945 +
  946 + @since Available in KSYMoviePlayerController 1.0 and later.
  947 + */
  948 +// Returns the current playback state of the movie player.
  949 +- (MPMoviePlaybackState)playbackState{
  950 + return _player.playbackState;
  951 +}
  952 +
  953 +/**
  954 + @abstract 当前网络加载情况
  955 + @discussion 可以通过该属性获取视频加载情况:
  956 +
  957 + <pre><code>
  958 + typedef NS_OPTIONS(NSUInteger, MPMovieLoadState) {
  959 + MPMovieLoadStateUnknown = 0, // 加载情况未知
  960 + MPMovieLoadStatePlayable = 1 << 0, // 加载完成,可以播放
  961 + MPMovieLoadStatePlaythroughOK = 1 << 1, // 加载完成,如果shouldAutoplay为YES,将自动开始播放
  962 + MPMovieLoadStateStalled = 1 << 2, // 如果视频正在加载中
  963 + } NS_DEPRECATED_IOS(3_2, 9_0);
  964 + </code></pre>
  965 + @discussion 通知:
  966 +
  967 + * MPMoviePlayerLoadStateDidChangeNotification,当加载状态变化时提供通知
  968 +
  969 + @since Available in KSYMoviePlayerController 1.0 and later.
  970 + */
  971 +// Returns the network load state of the movie player.
  972 +- (MPMovieLoadState)loadState{
  973 + return _player.loadState;
  974 +}
  975 +
  976 +
893 #pragma mark - 方法 977 #pragma mark - 方法
894 /* 978 /*
895 * 准备视频播放 979 * 准备视频播放
@@ -942,4 +1026,23 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang @@ -942,4 +1026,23 @@ NSString * const CNLiveHostStatusChangedNotification = @&quot;CNLiveAnchorStatusChang
942 1026
943 } 1027 }
944 1028
  1029 +/**
  1030 + @abstract 重新启动拉流
  1031 + @param aUrl 视频播放地址,该地址可以是本地地址或者服务器地址.如果为nil,则使用前一次播放地址
  1032 + @discussion 调用场景如下:
  1033 +
  1034 + * 当播放器调用方发现卡顿时,可以主动调用
  1035 + * 当估计出更优质的拉流ip时,可以主动调用
  1036 + * 当发生WiFi/3G网络切换时,可以主动调用
  1037 + * 当播放器回调体现播放完成时,可以主动调用
  1038 + * 播放器SDK不会自动调用reload功能
  1039 +
  1040 + @warning 该方法由金山云引入,不是原生系统接口
  1041 + @since Available in KSYMoviePlayerController 1.0 and later.
  1042 + */
  1043 +- (void)reload:(NSURL *)aUrl {
  1044 + [_player reload:aUrl];
  1045 +
  1046 +}
  1047 +
945 @end 1048 @end
CNLivePlayer/Classes/Player/CNLivePlayerUrl.h
@@ -18,12 +18,12 @@ @@ -18,12 +18,12 @@
18 #define StatAppVersion ([[[NSBundle mainBundle] infoDictionary] objectForKey: @"CFBundleShortVersionString"]) 18 #define StatAppVersion ([[[NSBundle mainBundle] infoDictionary] objectForKey: @"CFBundleShortVersionString"])
19 19
20 #pragma mark - 鉴权 20 #pragma mark - 鉴权
21 -#define authUrl [NSString stringWithFormat:@"%@/platform/valid", [CNLivePlayerManager manager].isTestEnvironment ? @"http://test.open.cnlive.com/openapi/api2" : @"http://api.cnlive.com/open/api2"] 21 +#define AuthUrl [NSString stringWithFormat:@"%@/platform/valid", [CNLivePlayerManager manager].isTestEnvironment ? @"http://test.open.cnlive.com/openapi/api2" : @"http://api.cnlive.com/open/api2"]
22 22
23 #pragma mark - 点播 23 #pragma mark - 点播
24 -#define vodUrl [CNLivePlayerManager manager].isTestEnvironment ? @"http://test.open.cnlive.com/openapi/api2/vod_ips/vodplayByAPP":@"http://api.cnlive.com/open/api2/vod_ips/vodplayByAPP" 24 +#define VodUrl [CNLivePlayerManager manager].isTestEnvironment ? @"http://test.open.cnlive.com/openapi/api2/vod_ips/vodplayByAPP":@"http://api.cnlive.com/open/api2/vod_ips/vodplayByAPP"
25 25
26 #pragma mark - 直播 26 #pragma mark - 直播
27 -#define liveUrl [CNLivePlayerManager manager].isTestEnvironment ? @"http://test.open.cnlive.com/openapi/api2/live_ips/liveplayByAPP":@"http://api.cnlive.com/open/api2/live_ips/liveplayByAPP" 27 +#define LiveUrl [CNLivePlayerManager manager].isTestEnvironment ? @"http://test.open.cnlive.com/openapi/api2/live_ips/liveplayByAPP":@"http://api.cnlive.com/open/api2/live_ips/liveplayByAPP"
28 28
29 #endif /* CNLivePlayerUrl_h */ 29 #endif /* CNLivePlayerUrl_h */
Example/CNLivePlayer/CNLiveAppDelegate.m
@@ -18,7 +18,7 @@ @@ -18,7 +18,7 @@
18 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 18 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
19 { 19 {
20 // Override point for customization after application launch. 20 // Override point for customization after application launch.
21 - [CNLivePlayerManager setAppId:CNLivePlayer_AppId appKey:CNLivePlayer_AppKey isTestEnvironment:YES openCache:NO]; 21 + [CNLivePlayerManager setAppId:CNLivePlayer_AppId appKey:CNLivePlayer_AppKey isTestEnvironment:YES];
22 22
23 return YES; 23 return YES;
24 } 24 }
Example/CNLivePlayer/CNLivePlayerController.m
@@ -24,13 +24,14 @@ @@ -24,13 +24,14 @@
24 24
25 // Do any additional setup after loading the view. 25 // Do any additional setup after loading the view.
26 26
27 - _player = [[CNLivePlayer alloc]initVodPlayerWithVideoId:@"82_c8ff347048414b7295cef882f8361073" authSuccess:^{ 27 + self.player = [[CNLivePlayer alloc]initVodPlayerWithVideoId:@"82_c8ff347048414b7295cef882f8361073" authSuccess:^{
28 _player.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width*9/16.0); 28 _player.view.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.width*9/16.0);
29 [_player prepareToPlay]; 29 [_player prepareToPlay];
30 - [self.view addSubview:_player.view];  
31 } authFailure:^(NSDictionary * _Nonnull errorInfo) { 30 } authFailure:^(NSDictionary * _Nonnull errorInfo) {
32 31
33 }]; 32 }];
  33 + [self.view addSubview:self.player.view];
  34 +
34 35
35 //1066_716fabeaafb64236b60ecf74167c5c96 36 //1066_716fabeaafb64236b60ecf74167c5c96
36 //82_c8ff347048414b7295cef882f8361073 37 //82_c8ff347048414b7295cef882f8361073