最近开发一个直播项目,百度云推流SDK(推流) + 百度云流媒体 + ijkplayer(拉流) 简单的实现了直播功能。在这里说一下用法过程。
首先注册百度云账号按照推流SDK配置Xcode环境,百度云推流SDK开发文档 ,下面说一下用法:
1.配置一下plist文件
2.导入百度云推流SDKdemo里面的文件
3.在需要直播的点击事件里写上一下代码
NSString* name;
if (self.model.direction == DirectionPortrait) {
name = @"StreamingPortrait";
} else {
name = @"StreamingLandscape";
}
dispatch_async(dispatch_get_main_queue(), ^{
UIStoryboard* board = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
StreamingViewController* vc = (StreamingViewController*)[board instantiateViewControllerWithIdentifier:name];
StreamingViewModel* vm = [[StreamingViewModel alloc] initWithSettingViewModel:self.model];
vc.model = vm;
[self.navigationController pushViewController:vc animated:YES];
});
4.初始化推流参数等
- (void)viewDidLoad {
[super viewDidLoad];
[self initialLivePlay];//初始化推流参数
}
#pragma mrak -- 直播推流
-(void)initialLivePlay{//初始化推流参数
self.model = [[SettingViewModel alloc] init];
self.navigationController.delegate = self;
self.model.url = @"rtmp://push.bcelive.com/live/zbgxhodqmyinbfodpv";//推流地址
self.model.resolution = (Resolution)720;//1080p,720p
self.model.direction = (Direction)0;//横竖屏
NSLog(@"横竖屏%ld",(long)self.model.direction);
}
- (void)navigationController:(UINavigationController *)navigationController
willShowViewController:(UIViewController *)viewController
animated:(BOOL)animated {
if (self.model.direction == DirectionPortrait) {
return;
}
if (viewController != self) {
[self rotateVC:M_PI_2];
} else {
[self rotateVC:-M_PI_2];
}
}
- (void)rotateVC:(CGFloat)angle {
CGSize screenSize = [UIScreen mainScreen].bounds.size;
CGPoint center = CGPointMake(screenSize.width / 2, screenSize.height / 2);
self.navigationController.view.center = center;
CGAffineTransform transform = CGAffineTransformMakeRotation(angle);
if (angle < 0) {
transform = CGAffineTransformIdentity;
}
self.navigationController.view.transform = transform;
CGRect bounds = CGRectMake(0, 0, screenSize.height , screenSize.width);
if (angle < 0) {
bounds = CGRectMake(0, 0, screenSize.width , screenSize.height);
}
self.navigationController.view.bounds = bounds;
}
以上,推流就完成了。
拉流呢,我看了看百度的拉流,有点麻烦,还不如bilibili的ijkplayer,关于IJKMediaFramework的集成 , 链接里有介绍ijk的集成方法,也可以去下载IJKMediaFramework和播放代码 。