我一直就想当一个可以不动脑的程序猿,于是我决定给大家翻译一遍LFLiveKit,以便争取更多像我一样的人。
首先LFLiveKit支持rtmp,flv两种流类型,LFLiveSession是整个库文件的入口,包含有那么几个属性
@property (nullable,nonatomic, weak) delegate;//代理方法 稍后介绍
@property (nonatomic, assign) BOOL running;//控制直播是开还是关的状态
@property (nonatomic, strong,null_resettable) UIView *preView;//视频图层
@property (nonatomic, assign) AVCaptureDevicePosition captureDevicePosition;//摄像头方向
@property (nonatomic, assign) BOOL beautyFace;//美颜开关
@property (nonatomic,assign) BOOL muted;//静音开关
@property (nullable,nonatomic, strong,readonly) LFLiveStreamInfo * streamInfo;//控制直播流的信息
@property (nonatomic,assign,readonly) LFLiveState state;//直播流上传的状态
@property (nonatomic,assign) BOOL showDebugInfo;//
@property (nonatomic,assign) NSUInteger reconnectInterval;//重连间隔
@property (nonatomic,assign) NSUInteger reconnectCount;//重连次数
代理方法
- (void)liveSession:(nullable LFLiveSession *)session liveStateDidChange:(LFLiveState)state; //监听直播的状态
- (void)liveSession:(nullable LFLiveSession *)session debugInfo:(nullable LFLiveDebug*)debugInfo;
- (void)liveSession:(nullable LFLiveSession*)session errorCode:(LFLiveSocketErrorCode)errorCode;
初始化方法
- (nullable instancetype)initWithAudioConfiguration:(nullable LFLiveAudioConfiguration*)audioConfiguration videoConfiguration:(nullable LFLiveVideoConfiguration*)videoConfiguration liveType:(LFLiveType)liveType //初始化session的方法 三个参数分别是 视频 音频 和 流类型设置
- (void)startLive:(nonnull LFLiveStreamInfo*)streamInfo;//开始直播
- (void)stopLive;//停止直播
demo
//初始化preView
-(UIView *)livingPreView{
if (!_livingPreView) {
UIView *livingPreView = [[UIView alloc]initWithFrame:self.view.bounds];
livingPreView.backgroundColor = [UIColor clearColor];
livingPreView.autoresizingMask = UIViewAutoresizingFlexibleWidth| UIViewAutoresizingFlexibleHeight;
[self.view insertSubview:livingPreView atIndex:0];
_livingPreView = livingPreView;
}
return _livingPreView;
}
//初始化session
-(LFLiveSession *)session{
if (!_session) {
//采用默认的音视频质量 LFLiveAudioConfiguration(音频设置) LFLiveVideoConfiguration(视频质量)
_session = [[LFLiveSession alloc]initWithAudioConfiguration: [LFLiveAudioConfiguration defaultConfiguration] videoConfiguration:[LFLiveVideoConfiguration defaultConfigurationForQuality:LFLiveVideoQuality_Medium2] liveType:LFLiveRTMP];
//设置代理
_session.delegate = self;
_session.running = YES;
_session.preView = self.livingPreView;
}
return _session;
}
- (void)viewDidLoad {
[super viewDidLoad];
LFLiveStreamInfo *stream = [[LFLiveStreamInfo alloc]init];
stream.url = @"rtmp://10.130.28.4410.130.28.44"
self.session.beautyFace = yes;
[self.session startLive:stream];
[self setup];
}
第一次写博客 不会排版 这是session.h文件 下面我会继续给大家翻译 翻译完会为大家带来一点我自己的理解