-
Notifications
You must be signed in to change notification settings - Fork 271
bypassRecord
Franken Zeng edited this page Nov 18, 2016
·
4 revisions
旁路录像是指在开始推流之后, 启动录像可以将推流的视频内容同步保存为本地文件, 也称为边推边录.
目前支持保存为本地的MP4文件和flv文件.
必须要启动推流后才能开始录像, 结束推流时, 会强制停止录像.
v1.9.0(含)后支持该功能
在推流的基础类中和启动和停止推流的API, 平行的增加了一组启动和停止旁路录像的API
_bypassRecFile =[NSHomeDirectory() stringByAppendingString:@"/Documents/rec.mp4"];
NSURL *url =[[NSURL alloc] initFileURLWithPath:_bypassRecFile];
[_kit.streamerBase startBypassRecord:url];
// ...
[_kit.streamerBase stopBypassRecord];
涉及接口主要是:
- 通过状态属性来查询当前旁路录像的状态
KSYRecordState bypassRecordState;
- 状态值说明
KSYRecordState 取值 | 说明 |
---|---|
KSYRecordStateIdle | 初始状态 |
KSYRecordStateRecording | 录像中 |
KSYRecordStateStopped | 录像停止 |
KSYRecordStateError | 录像失败 |
- 通过状态回调函数来接收状态变化通知
_kit.streamerBase.bypassRecordStateChange = ^(KSYRecordState state) {
[self onBypassRecordStateChange:state];
};
- (void) onBypassRecordStateChange: (KSYRecordState) newState {
if (newState == KSYRecordStateRecording){
NSLog(@"start bypass record");
}
else if (newState == KSYRecordStateStopped) {
NSLog(@"stop bypass record");
[self saveVideoToAlbum:_bypassRecFile];
}
else if (newState == KSYRecordStateError) {
NSLog(@"bypass record error");
}
}
当状态通知为KSYRecordStateError时 , 可以通过错误码查询接口判断具体的错误类型。
KSYRecordStateError取值 | 说明 |
---|---|
KSYRecordErrorNone | 无错误 |
KSYRecordErrorPathInvalid | 地址错误 |
KSYRecordErrorFormatNotSupport | 格式不支持 |
KSYRecordErrorInternal | 内部错误 |
通过如下接口查询, 返回结果是单位为秒的浮点数
_kit.streamerBase.bypassRecordDuration;
注意: 由于是将录像的内容保存在本地, 请注意限制时长, 避免手机存储满.