iOS SDK
优质
小牛编辑
133浏览
2023-12-01
手机推拉流iOS SDK文档
目录
如何接入
环境需求:
- iOS系统版本8.0及以上
- 机器型号 iPhone 5S及以上
- CPU架构支持 ARMv7、ARMv7s、ARM64
- 集成工具 Xcode8.0及以上
- bitcode 关闭
接入步骤
将
IJKMediaFramework.framework
、MDLiveEngine.framework
、IJKMediaFrameworkWithSSL.framework
、Accelerate.framework
、AudioToolbox.framework
等库文件和资源文件拖入项目文件夹在项目根路径下运行如下命令:
pod init
然后在修改根目录下的Profile文件添加以下依赖:
pod 'MBProgressHUD', '~> 1.1.0' pod 'Masonry'
之后在项目跟路径下运行如下命令:
pod install
在
Build Settings
中关闭Bitcode
在
info.plist
中添加获取摄像头、麦克风和相册权限的描述
推流配置
推流配置如下例:
MDPushConfig pushConfig;
memset(&pushConfig, 0, sizeof(pushConfig));
//设置音频采样率
pushConfig.audioSampleRate = 44100;
pushConfig.channel = 2;
//设置视频码率
pushConfig.videoBitRate = 9000* 1000;
//设置音频码率
pushConfig.audioBitRate = 96 * 1000;
//设置分辨率 默认为720P
pushConfig.pushSize = Preset1080x720;
//设置推流类型 默认音视频推流
pushConfig.streamType = MDPUSH_DEFAULT;
//设置推流地址
pushConfig.config.rtmpConfig.pushUrl = @"rtmp://xxxxx/xxxx/xxxx";
在配置好推流配置后,调用下例代码可以弹出推流页面:
//创建MDPusher
_livepush = [[MDLiveEngine alloc]init];
//设置摄像头 默认为前置摄像头
[_livepush startCaptureWithSizeType:kCaptureSize1280_720 fps:30 position:AVCaptureDevicePositionFront];
//设置推流方向是否为竖屏 默认为NO
_livepush.outputOrientation = UIInterfaceOrientationPortrait;
//设置推流配置
[_livepush startStreamPushWithConfig:pushConfig];
退出销毁
[_livepush stopStreamPush];
附加功能
1.静音
[_livepush enableMixingAudioStream:!btn.selected];
2.开关闪光灯
if (_livepush.cameraPosition == AVCaptureDevicePositionBack)
{
_livepush.torchOn = btn.selected;
}
else
{
UIAlertView* view = [[UIAlertView alloc]initWithTitle:@"提示" message:@"闪关灯只在后置摄像头有效" delegate:nil cancelButtonTitle:@"确定" otherButtonTitles: nil];
[view show];
}
3.切换摄像头
if (_livepush.cameraPosition == AVCaptureDevicePositionBack)
{
_livepush.cameraPosition = AVCaptureDevicePositionFront;
}else
{
_livepush.cameraPosition = AVCaptureDevicePositionBack;
}
拉流步骤
获取playerView,设置播放地址并播放
_player = [[IJKFFMoviePlayerController alloc]initWithContentURLString:self.textfield.text withOptions:nil]; [_player setOptionIntValue:1 forKey:@"videotoolbox" ofCategory:kIJKFFOptionCategoryPlayer]; [_player setPlayerOptionIntValue:5000 forKey:@"max_cached_duration"]; _player.view.frame = self.view.bounds; [_player prepareToPlay];
重新播放
if (_player) { [_player stop]; [_player shutdown]; _player = nil; } [self playVideo];
结束播放
if (_player) { [_player stop]; [_player shutdown]; _player = nil; }
错误码说明
//包发送错误 kLiveEngineSendPacketError //与服务器握手失败 kLiveEngineConnectError //停止推流错误 kLiveEngineStopPushError //视频录制错误 kLiveEngineInfoRecodeError //电话,闹钟等音频抢占导致音频终止 kLiveEngineInfoAudioInterruption