? ? 我一直就想當(dāng)一個(gè)可以不動(dòng)腦的程序猿除嘹,于是我決定給大家翻譯一遍L(zhǎng)FLiveKit展鸡,以便爭(zhēng)取更多像我一樣的人。
? ? 首先LFLiveKit支持rtmp捺癞,flv兩種流類型夷蚊,LFLiveSession是整個(gè)庫(kù)文件的入口,包含有那么幾個(gè)屬性
@property (nullable,nonatomic, weak) delegate;//代理方法 稍后介紹
@property (nonatomic, assign) BOOL running;//控制直播是開(kāi)還是關(guān)的狀態(tài)
@property (nonatomic, strong,null_resettable) UIView *preView;//視頻圖層
@property (nonatomic, assign) AVCaptureDevicePosition captureDevicePosition;//攝像頭方向
@property (nonatomic, assign) BOOL beautyFace;//美顏開(kāi)關(guān)
@property (nonatomic,assign) BOOL muted;//靜音開(kāi)關(guān)
@property (nullable,nonatomic, strong,readonly) LFLiveStreamInfo * streamInfo;//控制直播流的信息
@property (nonatomic,assign,readonly) LFLiveState state;//直播流上傳的狀態(tài)
@property (nonatomic,assign) BOOL showDebugInfo;//
@property (nonatomic,assign) NSUInteger reconnectInterval;//重連間隔?
@property (nonatomic,assign) NSUInteger reconnectCount;//重連次數(shù)
代理方法
- (void)liveSession:(nullable LFLiveSession *)session liveStateDidChange:(LFLiveState)state; //監(jiān)聽(tīng)直播的狀態(tài)
- (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的方法 三個(gè)參數(shù)分別是 視頻 音頻 和 流類型設(shè)置
- (void)startLive:(nonnull LFLiveStreamInfo*)streamInfo;//開(kāi)始直播
- (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) {
? ? ? ? ? ? ? //采用默認(rèn)的音視頻質(zhì)量 LFLiveAudioConfiguration(音頻設(shè)置) ? ? ? ? ? ? ? ? ?LFLiveVideoConfiguration(視頻質(zhì)量)
? ? ? ? ? ? ? _session = [[LFLiveSession alloc]initWithAudioConfiguration: ? ?[LFLiveAudioConfiguration defaultConfiguration] videoConfiguration:[LFLiveVideoConfiguration defaultConfigurationForQuality:LFLiveVideoQuality_Medium2] liveType:LFLiveRTMP];
? ? ? ? ? ? ?//設(shè)置代理
? ? ? ? ? ? ? ?_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];
}
第一次寫博客 ?不會(huì)排版 這是session.h文件 下面我會(huì)繼續(xù)給大家翻譯 翻譯完會(huì)為大家?guī)?lái)一點(diǎn)我自己的理解