前提:
有自己的直播服务器,或者本地搭建一个服务器进行测试用;代码里面没有给出服务器链接,请谅解。
代码下载地址:延哥直播代码,点击闪现!!!(请给星星)
下面开始介绍使用方法:
1、使用cocoapods添加第三方库:
pod 'Masonry' (按钮布局用到了,直播核心没有用到)
pod 'IQKeyboardManager'
pod 'LFLiveKit'
pod 'BarrageRenderer'
2、在控制器里添加推流界面:
2.1、导入头文件:
#import "CZYNavigationViewController.h"
#import "LFLiveSession.h"
@property (nonatomic, strong) LFLiveSession * session;
@property (nonatomic, strong) LFLiveStreamInfo *streamInfo;
2.2、创建推流界面:
-(void)startShow
{
LFLiveStreamInfo *streamInfo = [LFLiveStreamInfo new];
_streamInfo = streamInfo;
_streamInfo.url = @"自己直播服务器地址";
[self.session startLive:_streamInfo];
}
3、由上面2.2可以看出需要加载self.session类,所以要有一下代码:
- (LFLiveSession*)session {
if (!_session) {
// 横屏拍摄、推流
_session = [[LFLiveSession alloc]initWithAudioConfiguration:[LFLiveAudioConfiguration defaultConfigurationForQuality: LFLiveAudioQuality_Medium] videoConfiguration:[LFLiveVideoConfiguration defaultConfigurationForQuality:LFLiveVideoQuality_High3 orientation:UIInterfaceOrientationLandscapeRight ] liveType:LFLiveRTMP];
// 竖屏拍摄、推流
// _session = [[LFLiveSession alloc]initWithAudioConfiguration:[LFLiveAudioConfiguration defaultConfigurationForQuality: LFLiveAudioQuality_Medium] videoConfiguration:[LFLiveVideoConfiguration defaultConfigurationForQuality:LFLiveVideoQuality_High3 orientation:UIInterfaceOrientationPortrait ] liveType:LFLiveRTMP];
}
_session.running = YES;
_session.preView = self.view;
_session.delegate = self;
}
return _session;
}