CNLivePlayer.h
5.89 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
//
// CNLivePlayer.h
// CNLivePlayer_Example
//
// Created by CNLive-zxw on 2019/7/26.
// Copyright © 2019 153993236@qq.com. All rights reserved.
//
#import <Foundation/Foundation.h>
#import <libksygpulive/KSYMoviePlayerController.h>
#import "KSYMoviePlayerDefines.h"
// 枚举定义
#import "CNLivePlayerDefines.h"
// 播放器管理类
#import "CNLivePlayerManager.h"
//缓存url
#import "CNLivePlayerDBTool.h"
//缓存h视频
#import "CNLiveHTTPProxyService.h"
NS_ASSUME_NONNULL_BEGIN
/*
* 获取主播状态通知
*/
UIKIT_EXTERN NSString *const CNLiveHostStatusChangedNotification;
/*
* 成功回调
*/
typedef void(^AuthSuccessBlock)(void);
/*
* 失败回调
*/
typedef void(^AuthFailureBlock)(NSDictionary *errorInfo);
@interface CNLivePlayer : NSObject
/*
* 播放器类型
*/
@property (nonatomic, assign, readonly) CNLivePlayerType type;
/*
* 播放器
*/
@property (nonatomic, strong) KSYMoviePlayerController *player;
#pragma mark - 初始化方法
/*
* 初始化播放器并设置播放地址
*
* url 视频url
*
*/
- (instancetype)initWithContentURL:(NSURL *)url;
/* 初始化点播播放器 初始化成功后才能对播放器进行设置(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay)
*
* videoId 视频Id
* authSuccess 初始化成功block
* authFailed 初始化失败block 回调一个errorInfo的字典
*
*/
- (instancetype)initVodPlayerWithVideoId:(NSString *)videoId authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock;
/* 初始化直播播放器(* 以channelId播放) 初始化成功后才能对播放器进行设置(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay)
*
* channelId 直播视频Id (注* 若agree为YES时,必传,用于获取主播状态; 若agree为NO,可不传)
* activityId 活动Id
* agree 是否允许获取主播状态 YES:获取 NO:不获取
* authSuccess 初始化成功block
* authFailed 初始化失败block 回调一个errorInfo的字典
*
* result 获取主播状态 YES:获取状态成功
* NO:获取失败,不影响视频播放,但是获取不到主播离开、回来、直播结束等通知。
* 可通过- (void)getHostStatus:(void(^)(BOOL result))result;方法重新获取
*/
- (instancetype)initLivePlayerWithChannelId:(NSString *)channelId activityId:(NSString *)activityId hostStatus:(BOOL)agree authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock getHostStatusResult:(void(^)(BOOL result))result;
/* 初始化音频播放器 初始化成功后才能对播放器进行设置(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay)
*
* contentId 音频Id
* authSuccess 初始化成功block
* authFailed 初始化失败block 回调一个errorInfo的字典
*
*/
- (instancetype)initAudioPlayerWithAudioId:(NSString *)audioId authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock;
#pragma mark - 属性
/**
@abstract 正在播放的视频文件的地址,该地址可以是本地地址或者服务器地址。
*/
@property (nonatomic, readonly) NSURL *contentURL;
/**
@abstract 包含视频播放内容的VIEW(只读)。
@discussion view的使用逻辑:
* 可以通过frame设置view大大小
* 使用[scalingMode]([KSYMoviePlayerController scalingMode]) 可以更改视频内容在VIEW中的显示情况
@see scalingMode
*/
// The view in which the media and playback controls are displayed.
@property (nonatomic, strong, readonly) UIView *view;
/*
* 主播直播状态(只读)
*/
@property (nonatomic, assign, readonly) CNLiveHostStatus hostStatus;
/**
@abstract 是否静音
@discussion
* 默认不静音
* [prepareToPlay]方法前设置即生效,也可以在播放过程中动态切换
*/
@property (nonatomic) BOOL shouldMute;
/**
@abstract 是否循环播放
@discussion 默认不循环
* 只在[prepareToPlay]调用前设置生效;
* 只有点播生效,直播场景请勿设置
*/
@property (nonatomic) BOOL shouldLoop;
/**
@abstract 指定逆时针旋转角度,只能是0/90/180/270, 不符合上述值不进行旋转
*/
@property (nonatomic, assign) int rotateDegress;
/**
@abstract 是否打断其他后台的音乐播放
@discussion 也可以理解为是否允许和其他音频同时播放
@discussion YES:开始播放时,会打断其他的后台播放音频,也会被其他音频播放打断
@discussion NO: 可以与其他后台播放共存,相互之间不会被打断
@discussion 默认为YES
*/
@property (nonatomic) BOOL bInterruptOtherAudio;
/*
* 查询视频准备是否完成(只读)
*/
@property (nonatomic, readonly) BOOL isPreparedToPlay;
#pragma mark - 方法
/*
* 获取主播状态(离开/已结束)
*/
- (void)getHostStatus:(void(^)(BOOL result))result;
/* 给播放器设置内容id 设置成功后才能播放(如:自动播放、是否开启硬件解码等)和调用准备播放视频方法(prepareToPlay)
* 切换视频
* contentId 内容Id
* type 内容类型
*
*/
- (void)setPlayerWithContentId:(NSString *)contentId type:(CNLivePlayerType)type authSuccess:(AuthSuccessBlock)authSuccessBlock authFailure:(AuthFailureBlock)authFailureBlock;
/*
* 销毁播放器
*/
- (void)destroyPlayer;
/*
* 准备视频播放
* MPMediaPlaybackIsPreparedToPlayDidChangeNotification 播放器完成对视频文件的初始化时发送通知
*/
- (void)prepareToPlay;
/*
* 视频播放
*/
- (void)play;
/*
* 当前播放器是否在播放
*/
- (BOOL)isPlaying;
/*
* 视频暂停
*/
- (void)pause;
/*
* 视频停止
*/
- (void)stop;
/*
* 视频截图
*/
- (UIImage *)thumbnailImageAtCurrentTime;
@end
NS_ASSUME_NONNULL_END