本地视频
远程视频
这也是坑。。。
以一般人的思维,创建完会议室,然后加入房间,就跳转到视频页面,,显示本地自己的视频图像,,然后有人加进来的话再把对方的视频图像显示出来。
然而。。。不能这么做。就是在这里我卡了两天。。。。。。。真想打人。
创建加入会议房间必须在同一个页面完成,否则会出现本地视频代理方法不走。。然后你就获取不到本地流,显示不出来。。。
首先需要
#import "NTESGLView.h"
这个东西(ijkl)这也是坑啊。。。倒入的时候报错。。相对路径和绝对路径的错
解决方法就是直接把相对路径去掉
#include "ijksdl_vout.h" 这样子。 就可以了。
不想写了直接上代码了
.m文件
//
// LSXVideoChatVC.m
// wxf
//
// Created by 医联通 on 17/10/13.
// Copyright © 2017年 lsx. All rights reserved.
//
#import "LSXVideoChatVC.h"
#import <NIMAVChat/NIMAVChat.h>
#import <NIMSDK/NIMSDK.h>
#import "NTESGLView.h"
#import "NTESBundleSetting.h"
@interface LSXVideoChatVC ()<NIMNetCallManagerDelegate>
@property (nonatomic, strong) NTESGLView *videoView;
@property (nonatomic, strong) UIView * localView;
@end
@implementation LSXVideoChatVC
- (void)viewDidLoad {
[super viewDidLoad];
_localView=[UIView new];
_videoView=[[NTESGLView alloc]initWithFrame:CGRectMake(0, 64,SCREEN_WIDTH, SCREEN_HEIGHT/2)];
_videoView.backgroundColor=LineColor;
[self.view addSubview:_videoView];
if([_CreatOrJoin isEqualToString:@"1"]){
_localView.frame=_videoView.bounds;
}else{
_localView.frame=CGRectMake(SCREEN_WIDTH-110, 74, 100, 100);
}
[[NIMAVChatSDK sharedSDK].netCallManager addDelegate:self];
if([_CreatOrJoin isEqualToString:@"1"]){
//创建
[self reserveMeetingWithRoomId:_roomId];
}else{
//加入
NIMNetCallMeeting *meeting = [[NIMNetCallMeeting alloc] init];
meeting.name =_roomId;
[self joinNetCallWithRMeeting:meeting];
}
}
//
//-(void)CreatButtons{
//
// UIButton * btn1=[UIButton new];
// [_videoView addSubview:btn1];
// btn1.frame=CGRectMake(10, 74, <#CGFloat width#>, <#CGFloat height#>)
//
//}
//预订会议(创建会议)
- (void)reserveMeetingWithRoomId:(NSString *)roomId{
NIMNetCallMeeting *meeting = [[NIMNetCallMeeting alloc] init];
meeting.name = roomId;
meeting.type = NIMNetCallMediaTypeVideo;
meeting.ext = @"哈哈哈哈";
meeting.actor = YES;
[[NIMAVChatSDK sharedSDK].netCallManager reserveMeeting:meeting completion:^(NIMNetCallMeeting * _Nonnull meeting, NSError * _Nonnull error) {
if (!error) {
NSLog(@"预定成功 ,进入房间");
[self joinNetCallWithRMeeting:meeting];
} else {
if (error.code == 417) {
[self joinNetCallWithRMeeting:meeting];
} else {
NSLog(@"预定房间失败");
}
}
}];
}
//加入会议相关方法
- (void)joinNetCallWithRMeeting:(NIMNetCallMeeting *)rMeeting {
NIMNetCallOption *callOption =[[NIMNetCallOption alloc]init];
// 发送视频质量(SDK会处理 有可能无效)
//callOption.preferredVideoQuality =NIMNetCallVideoQualityDefault;
// 禁止剪裁
// callOption.disableVideoCropping =NO;
// 自动旋转远端画面
callOption.autoRotateRemoteVideo =YES;
// 期望的视频编码器
callOption.preferredVideoEncoder =NIMNetCallVideoCodecDefault;
// 期望的视频解码器
callOption.preferredVideoDecoder =NIMNetCallVideoCodecDefault;
// 初始打开摄像头,
callOption.videoCaptureParam.startWithCameraOn =YES;
// 启用互动直播
callOption.enableBypassStreaming =YES;
// 互动直播推流地址
callOption.bypassStreamingUrl =nil;
// 是否在服务器录制音频
callOption.serverRecordAudio =YES;
callOption.autoDeactivateAudioSession = NO;
// 是否在服务器录制视频
callOption.serverRecordVideo =YES;
callOption.videoCaptureParam = [self videoCaptureParam];
// 加入会议的类型->音频/视频
rMeeting.type =NIMNetCallMediaTypeVideo;
// 是否发送音视频数据
rMeeting.actor = YES;
// 网路电话配置
rMeeting.option = callOption;
//进入房间聊天
[[NIMAVChatSDK sharedSDK].netCallManager joinMeeting:rMeeting completion:^(NIMNetCallMeeting * _Nonnull meeting, NSError * _Nonnull error) {
if (!error) {
NSLog(@"进入成功");
NSLog(@"callID====%llu---name===--%@",meeting.callID,meeting.name);
} else {
NSLog(@"进入失败");
[self reserveMeetingWithRoomId:_roomId];
}
}];
}
//音视频配置
- (NIMNetCallVideoCaptureParam *)videoCaptureParam{
NIMNetCallVideoCaptureParam *param = [[NIMNetCallVideoCaptureParam alloc] init];
param.videoCrop = [[NTESBundleSetting sharedConfig] videochatVideoCrop];
// 使用后置摄像头开始视频, 默认是 YES
param.startWithBackCamera = [[NTESBundleSetting sharedConfig] startWithBackCamera];
param.preferredVideoQuality = [[NTESBundleSetting sharedConfig] preferredVideoQuality];
param.provideLocalVideoProcess = [[NTESBundleSetting sharedConfig] provideLocalProcess];
param.preferredVideoQuality = NIMNetCallVideoQualityLow;
return param;
}
#pragma NIMNetCallManagerDelegate
/// 远程视频 (是控制远程视频流)
-(void)onRemoteYUVReady:(NSData *)yuvData width:(NSUInteger)width height:(NSUInteger)height from:(NSString *)user{
if (yuvData) {
_localView.frame=CGRectMake(SCREEN_WIDTH-110, 74, 100, 100);
[_videoView render:yuvData width:width height:height];
}
}
/// 本地视频 (此处是控制本地视频流)
-(void)onLocalDisplayviewReady:(UIView *)displayView{
displayView.frame=_localView.bounds;
[_localView addSubview:displayView];
[_videoView addSubview:_localView];
}
-(void)viewWillDisappear:(BOOL)animated{
[self hzId:_hzId withType:@"2"];
[self MSUNetCallManagerLeaveMeeting];
}
//离开会议
- (void)MSUNetCallManagerLeaveMeeting {
NIMNetCallMeeting *meeting = [[NIMNetCallMeeting alloc] init];
meeting.name = _roomId;
[[NIMAVChatSDK sharedSDK].netCallManager leaveMeeting:meeting];
}
- (void)dealloc{
[[NIMAVChatSDK sharedSDK].netCallManager removeDelegate:self];
}
@end