-
Notifications
You must be signed in to change notification settings - Fork 271
retryConnect
Franken Zeng edited this page Jul 19, 2017
·
7 revisions
当推流过程中遇到一定错误时,需要重新推流。重试逻辑不包含在libksyguplive内,请自行完成重试逻辑。
- KSYStreamErrorCode_CONNECT_BREAK,网络连接断开(服务器关闭或者网络切换失败)
- KSYStreamErrorCode_AV_SYNC_ERROR,音视频同步失败
- KSYStreamErrorCode_CODEC_OPEN_FAILED,编码器启动失败(硬编容易出现,需要重试) 详细说明请见:http://ksvc.github.io/KSYLive_iOS/doc/html/Constants/KSYStreamErrorCode.html
监听KSYStreamStateDidChangeNotification,当回调中查询_kit.streamerBase.streamState状态,当streamState处于KSYStreamStateError时,处理具体的streamErrorCode错误码。
if(_kit.streamerBase.streamState == KSYStreamStateError) {
[self onStreamError:_kit.streamerBase.streamErrorCode];
}
只需要调用[KSYStreamerBase startStream:]
- (void) onStreamError:(KSYStreamErrorCode) errCode{
_ctrlView.lblStat.text = [_kit.streamerBase getCurKSYStreamErrorCodeName];
if (errCode == KSYStreamErrorCode_CONNECT_BREAK) {
// Reconnect
[self tryReconnect];
}
else if (errCode == KSYStreamErrorCode_AV_SYNC_ERROR) {
NSLog(@"audio video is not synced, please check timestamp");
[self tryReconnect];
}
else if (errCode == KSYStreamErrorCode_CODEC_OPEN_FAILED) {
NSLog(@"video codec open failed, try software codec");
_kit.streamerBase.videoCodec = KSYVideoCodec_X264;
[self tryReconnect];
}
}
- (void) tryReconnect {
dispatch_time_t delay = dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC));
dispatch_after(delay, dispatch_get_main_queue(), ^{
NSLog(@"try again");
_kit.streamerBase.bWithVideo = YES;
[_kit.streamerBase startStream:self.hostURL];
});
}