设为首页收藏本站

AnyChat技术支持论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
查看: 3017|回复: 2
打印 上一主题 下一主题

关于本地视频关闭后渲染UI的问题

[复制链接]

14

主题

87

帖子

258

积分

中级会员

Rank: 3Rank: 3

积分
258
跳转到指定楼层
楼主
发表于 2016-3-2 17:23:11 | 只看该作者 |只看大图 回帖奖励 |倒序浏览 |阅读模式
你好,我在进行视频通讯的时候,关闭本地视频后。当然修改本地视频的frame时(改小),UIView上原来的区域保留了视频最后一帧的图像。我想清除掉这个图像。请问请改如何处理呢?
                 

                   1                                                          2

你好,图1是正常的显示情况,图2中蓝色框的区域就是遗留在view上的最后一帧的图像。我现在想清空它, 不知道是 layer渲染的问题 还是 view的问题
下面是我的代码 麻烦你了。


//
//  VideoVC.m
//  MchatDemo
//
//  Created by kenshin2 on 16/2/18.
//  Copyright © 2016年 kenshin. All rights reserved.
//

#define heightMenu 170

//44 45 50、 50 51 56 、54 55 60、 三种灰黑背景色RGB
#define headBackA [UIColor colorWithRed:44.0/255 green:45.0/255 blue:50.0/255 alpha:1.0]
#define headBackB [UIColor colorWithRed:50.0/255 green:51.0/255 blue:56.0/255 alpha:1.0]
#define headBackC [UIColor colorWithRed:54.0/255 green:55.0/255 blue:60.0/255 alpha:1.0]

#define backColor [UIColor colorWithRed:32.0/255 green:33.0/255 blue:38.0/255 alpha:1.0]

#import "VideoVC.h"
#import <QuartzCore/QuartzCore.h>
#import <AVFoundation/AVFoundation.h>
#import "AppDelegate.h"
#import "ViewController.h"
#import "Tools.h"

#import "AnyChatPlatform.h"
#import "AnyChatDefine.h"
#import "AnyChatErrorCode.h"

@implementation VideoVC
{
    BOOL                isJingYin;
    BOOL                isHandFree;
    BOOL                isOnlyOnce;

    UIImageView         *imgJingYin;
    UIImageView         *imgHands;
    UIImageView         *imgVideoSwitch;
    UIImageView         *imgHangUp;
    UIImageView         *imgAddFriends;

    UIControl           *turnCamera;//切换摄像头
    UIControl           *ctrlAddFriends;

    UIView              *containUp;//下部UI的容器
    MZTimerLabel        *MZTtime;
    UILabel             *labTimer;
    UIControl           *ctrlHangUp;
    UIControl           *ctrljingYin;
    UIControl           *ctrlVideo;//本地视频开关
    UIControl           *ctrlMianTi;
    NSString            *speaker;//麦克风
    NSString            *receiver;//听筒

    //静音、 免提、 视频
    UILabel             *jingYinLab;
    UILabel             *mianTiLab;
    UILabel             *videoLab;

    //语音时的头像
    UIImageView         *headSelfImgV;
    UIImageView         *headTwoImgV;
    UIImageView         *headThreeImgV;
    UIImageView         *headFourImgV;
    UIImageView         *headFiveImgV;
    UIImageView         *headSixImgV;
    UIImageView         *headSevenImgV;
    UIImageView         *headEightImgV;

    NSMutableArray      *remoteVideos;
}

+ (BOOL) getCuPageIsVideoVC
{
    return isCuVideoVC;
}

#pragma mark 重连 在ViewController 中被调用
- (void) reConnectVideo
{
    [self openLocalMicrophone];//需要根据重连之前的状态来设置【是否静音】
    [self StartLocalVideoChat];//需要根据重连之前的状态来设置【是否打开视频】
    [self myEnterRoomChat];//初始化远端数据

}

- (void)viewDidLoad
{
    [super viewDidLoad];
    [self setUI];
//    [self StartLocalVideoChat];//  local Video[枚举出本地的 摄像头并使用]
    [self myEnterRoomChat];    //  iRemote Video
    [self openLocalMicrophone];
    [AnyChatPlatform SetSDKOptionInt:BRAC_SO_NETWORK_AUTORECONNECT :1];// 网络掉线自动重连功能控制
    isCuVideoVC = YES;
}

- (void)viewWillAppearBOOL)animated
{
    [super viewWillAppear:YES];
    [self performSelectorselector(delayCheckCuDeviceIsSupportVideoChat) withObject:self afterDelay:1.5f];

    //[远端进入时被调用]
    self.pvBlock =  ^(int targerUserID,int imgViewTag,VideoVC *videoVC)
    {
        NSMutableArray *onlyUsers = [[ViewController getSelfIsSingleObj] getOnlineUserArray];
        int cuUsers = (int)onlyUsers.count;
        NSLog(@"pvBlock 进入 当前有%d人—————————————————————————————————————————————————— == %@", cuUsers ,onlyUsers);
        if (cuUsers == 0)//自己
        {
            [videoVC selfChatUI];
        }
        if (cuUsers == 1)//2人
        {
            [videoVC twoUserChatUI];
        }
        if (cuUsers == 2)//3人
        {
            [videoVC threeUserChatUI];
        }
        if (cuUsers == 3)//4人
        {
            [videoVC fourUserChatUI];
        }
        if (cuUsers > 3 && cuUsers <= 8)//5~9人
        {
            [videoVC fiveToNineUserChatUI];
        }
        // request other user video
        [AnyChatPlatform UserSpeakControl: targerUserID:YES];
        NSLog(@"------------------------------------targerUserID == %d", targerUserID);
        switch (imgViewTag)
        {
            case 1 :
            {
                [AnyChatPlatform SetVideoPos:targerUserID: videoVC.iRemoteVideoView1:0:0:0:0];//视频
                videoVC.iRemoteVideoView1.tag = targerUserID;//用于当远端视频关闭时 为其设置背景头像
//                videoVC.iRemoteVideoView1.contentMode = UIViewContentModeScaleAspectFit;//显示样式
//                videoVC.iRemoteVideoView1.hidden = NO;
                break;
            }

            case 2 :
            {
                [AnyChatPlatform SetVideoPos:targerUserID: videoVC.iRemoteVideoView2:0:0:0:0];
                 videoVC.iRemoteVideoView2.tag = targerUserID;
//                videoVC.iRemoteVideoView2.hidden = NO;
                break;
            }

            case 3 :
            {
                [AnyChatPlatform SetVideoPos:targerUserID: videoVC.iRemoteVideoView3:0:0:0:0];
                 videoVC.iRemoteVideoView3.tag = targerUserID;
//                videoVC.iRemoteVideoView3.hidden = NO;
                break;
            }
            case 4 :
            {
                [AnyChatPlatform SetVideoPos:targerUserID: videoVC.iRemoteVideoView4:0:0:0:0];
                 videoVC.iRemoteVideoView4.tag = targerUserID;
//                videoVC.iRemoteVideoView4.hidden = NO;
                break;
            }
            case 5 :
            {
                [AnyChatPlatform SetVideoPos:targerUserID: videoVC.iRemoteVideoView5:0:0:0:0];
                 videoVC.iRemoteVideoView5.tag = targerUserID;
//                videoVC.iRemoteVideoView5.hidden = NO;
                break;
            }
            case 6 :
            {
                [AnyChatPlatform SetVideoPos:targerUserID: videoVC.iRemoteVideoView6:0:0:0:0];
                 videoVC.iRemoteVideoView6.tag = targerUserID;
//                videoVC.iRemoteVideoView6.hidden = NO;
                break;
            }
            case 7 :
            {
                [AnyChatPlatform SetVideoPos:targerUserID: videoVC.iRemoteVideoView7:0:0:0:0];
                 videoVC.iRemoteVideoView7.tag = targerUserID;
//                videoVC.iRemoteVideoView7.hidden = NO;
                break;
            }
            case 8 :
            {
                [AnyChatPlatform SetVideoPos:targerUserID: videoVC.iRemoteVideoView8:0:0:0:0];
                 videoVC.iRemoteVideoView8.tag = targerUserID;
//                videoVC.iRemoteVideoView8.hidden = NO;
                break;
            }
        }
        [AnyChatPlatform UserCameraControl:targerUserID : YES];

    };

    //[远端离开房间时被调用]
    self.aiBlock = ^(int imgViewTag,VideoVC *videoVC)
    {
        NSMutableArray *onlyUsers = [[ViewController getSelfIsSingleObj] getOnlineUserArray];
        int cuUsers = (int)onlyUsers.count;
        NSLog(@"aiBlock 离开 当前有%d人—————————————————————————————————————————————————— == %@", cuUsers, onlyUsers);
        if (cuUsers == 0)//自己
        {
            [videoVC selfChatUI];
        }
        if (cuUsers == 1)//2人
        {
            [videoVC twoUserChatUI];
        }
        if (cuUsers == 2)//3人
        {
            [videoVC threeUserChatUI];
        }
        if (cuUsers == 3)//4人
        {
            [videoVC fourUserChatUI];
        }
        if (cuUsers > 3 && cuUsers <= 8)
        {
            [videoVC fiveToNineUserChatUI];
        }


    };

    //用于设置免提
    NSMutableArray *EnumAudioArr = [AnyChatPlatform EnumAudioPlayback];
    NSLog(@"AudioPlayback %@", EnumAudioArr);
    speaker = [EnumAudioArr objectAtIndex:0];
    receiver = [EnumAudioArr objectAtIndex:1];

}

#pragma mark 初始化UI
- (void)setUI
{

    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];//[禁止屏幕休眠]
    self.view.backgroundColor = backColor;//背景色

    //远端视频for循环 当前控制到9个
    CGFloat widthV    = screenWidth/3.0;
    CGFloat splitLine = screenHeight - widthV*3;//分割线
    CGFloat margin    = 10;
    CGFloat sizeCtrl  = 44;

    self.theLocalView      = [[UIView alloc] initWithFrame:CGRectMake(0, 80, screenWidth/2, screenWidth/2)];

    self.iRemoteVideoView1 = [UIImageView new];
    self.iRemoteVideoView2 = [UIImageView new];
    self.iRemoteVideoView3 = [UIImageView new];
    self.iRemoteVideoView4 = [UIImageView new];
    self.iRemoteVideoView5 = [UIImageView new];
    self.iRemoteVideoView6 = [UIImageView new];
    self.iRemoteVideoView7 = [UIImageView new];
    self.iRemoteVideoView8 = [UIImageView new];

    //当关闭视频时,本地和远端UI都切换为对应用户的头像作为背景
    //初始化语音头像
    headSelfImgV  = [UIImageView new];
    headSelfImgV.image = [UIImage imageNamed"defaultHead"];

    headTwoImgV   = [UIImageView new];
    headThreeImgV = [UIImageView new];
    headFourImgV  = [UIImageView new];
    headFiveImgV  = [UIImageView new];
    headSixImgV   = [UIImageView new];
    headSevenImgV = [UIImageView new];
    headEightImgV = [UIImageView new];

    //切换摄像头
    turnCamera = [[UIControl alloc] initWithFrame:self.theLocalView.frame];
    [turnCamera addTarget:self actionselector(turnCameraPress) forControlEvents:UIControlEventTouchUpInside];
    //在绘制本地视频的回调函数中 添加本控件[如果在这里添加 会被 绘制的本地视频覆盖掉]

    //添加好友
    ctrlAddFriends = [[UIControl alloc] initWithFrame:CGRectMake(screenWidth - sizeCtrl, 0, sizeCtrl, sizeCtrl)];
    [ctrlAddFriends addTarget:self actionselector(addFriendsChat) forControlEvents:UIControlEventTouchUpInside];
    imgAddFriends = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 35, 35)];
    imgAddFriends.image = [UIImage imageNamed"barbuttonicon_addfriends"];
    [ctrlAddFriends addSubview:imgAddFriends];

    //下UI容器
    containUp = [[UIView alloc] initWithFrame:CGRectMake(0, screenHeight - splitLine, screenWidth, splitLine)];

    //聊天时长
    labTimer = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, screenWidth, sizeCtrl)];
    MZTtime = [[MZTimerLabel alloc] initWithLabel:labTimer];
    [MZTtime start];
    labTimer.textAlignment = NSTextAlignmentCenter;
    labTimer.font = [UIFont systemFontOfSize:14];
    labTimer.textColor = [UIColor whiteColor];
    [containUp addSubview:labTimer];


    //适配 (⊙﹏⊙)b
    CGFloat sizeHangUp = 120/2.5;
    CGFloat widthBtn   = 120/3;
    CGFloat heightBtn  = 156/3;
    CGFloat y_JMS      = splitLine + margin - sizeCtrl*3;//静音、免提、视频的y坐标
    NSLog(@"screenHeight == %f", screenHeight);
    if (screenHeight > 480)
    {
        sizeHangUp = 120/1.8;
        widthBtn   = 120/2;
        heightBtn  = 156/2;
        y_JMS      = splitLine/4;
    }

    //静音、
    ctrljingYin = [[UIControl alloc] initWithFrame:CGRectMake(screenWidth/4 - widthBtn/2, y_JMS, widthBtn, heightBtn)];
    [ctrljingYin addTarget:self actionselector(jingYinPress) forControlEvents:UIControlEventTouchUpInside];

    imgJingYin = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, widthBtn, heightBtn)];
    imgJingYin.image = [UIImage imageNamed"multitalkMuteMode"];

    jingYinLab = [[UILabel alloc] initWithFrame:CGRectMake(0, widthBtn, widthBtn, 20)];
    jingYinLab.text = @"静音";
    [self setLabStyle:jingYinLab];
    [ctrljingYin addSubview:imgJingYin];
    [ctrljingYin addSubview:jingYinLab];
    [containUp addSubview:ctrljingYin];

    //免提、
    ctrlMianTi = [[UIControl alloc] initWithFrame:CGRectMake(screenWidth/2 - widthBtn/2, y_JMS, widthBtn, heightBtn)];
    [ctrlMianTi addTarget:self actionselector(mianTiSwitch) forControlEvents:UIControlEventTouchUpInside];

    imgHands = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, widthBtn, heightBtn)];
    imgHands.image = [UIImage imageNamed"multitalkSpeakerMode"];

    mianTiLab = [[UILabel alloc] initWithFrame:CGRectMake(0, widthBtn, widthBtn, 20)];
    mianTiLab.text = @"免提";
    [self setLabStyle:mianTiLab];
    [ctrlMianTi addSubview:imgHands];
    [ctrlMianTi addSubview:mianTiLab];
    [containUp  addSubview:ctrlMianTi];

    //视频开关
    ctrlVideo = [[UIControl alloc] initWithFrame:CGRectMake(screenWidth/2 + screenWidth/4 - widthBtn/2, y_JMS, widthBtn, heightBtn)];
    [ctrlVideo addTarget:self actionselector(localVideoSwitch) forControlEvents:UIControlEventTouchUpInside];

    imgVideoSwitch = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, widthBtn, heightBtn)];
    imgVideoSwitch.image = [UIImage imageNamed:@"multitalkVideo"];

    videoLab = [[UILabel alloc] initWithFrame:CGRectMake(0, widthBtn, widthBtn, 20)];
    videoLab.text = @"视频";
    [self setLabStyle:videoLab];
    [ctrlVideo addSubview:imgVideoSwitch];
    [ctrlVideo addSubview:videoLab];
    [containUp addSubview:ctrlVideo];

    //挂断
    CGFloat xHangUp = screenWidth/2 - sizeHangUp/2;
    CGFloat yHangUp = splitLine - margin - sizeHangUp;

    ctrlHangUp = [[UIControl alloc] initWithFrame:CGRectMake(xHangUp, yHangUp, sizeHangUp, sizeHangUp)];
    [ctrlHangUp addTarget:self action:@selector(hangUp)     forControlEvents:UIControlEventTouchUpInside];
    [ctrlHangUp addTarget:self action:@selector(hangUpDown) forControlEvents:UIControlEventTouchDown];
    [ctrlHangUp addTarget:self action:@selector(hangUpUp)   forControlEvents:UIControlEventTouchUpOutside];

    imgHangUp = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, sizeHangUp, sizeHangUp)];
    imgHangUp.image = [UIImage imageNamed:@"callDeclineBtn"];


    [ctrlHangUp addSubview:imgHangUp];
    [containUp addSubview:ctrlHangUp];

    [self.view addSubview:self.theLocalView];

    remoteVideos = [NSMutableArray new];
    [remoteVideos addObject:self.iRemoteVideoView1];
    [remoteVideos addObject:self.iRemoteVideoView2];
    [remoteVideos addObject:self.iRemoteVideoView3];
    [remoteVideos addObject:self.iRemoteVideoView4];
    [remoteVideos addObject:self.iRemoteVideoView5];
    [remoteVideos addObject:self.iRemoteVideoView6];
    [remoteVideos addObject:self.iRemoteVideoView7];
    [remoteVideos addObject:self.iRemoteVideoView8];

//    [self.view addSubview:self.iRemoteVideoView1];
//    [self.view addSubview:self.iRemoteVideoView2];
//    [self.view addSubview:self.iRemoteVideoView3];
//    [self.view addSubview:self.iRemoteVideoView4];
//    [self.view addSubview:self.iRemoteVideoView5];
//    [self.view addSubview:self.iRemoteVideoView6];
//    [self.view addSubview:self.iRemoteVideoView7];
//    [self.view addSubview:self.iRemoteVideoView8];
    for (int i = 0; i < [remoteVideos count]; i++)
    {
        [self.view addSubview:[remoteVideos objectAtIndex:i]];
    }

    [self.view addSubview:containUp];
    [self.view addSubview:ctrlAddFriends];

    [self loadVoiceHeadImg];
}

- (void)setLabStyleUILabel *)lab
{
    lab.font          = [UIFont systemFontOfSize:12];
    lab.textColor     = [UIColor whiteColor];
    lab.textAlignment = NSTextAlignmentCenter;

}

#pragma mark 切换前后摄像头
- (void)turnCameraPress
{
    static int CurrentCameraDevice = 1;
    NSMutableArray* cameraDeviceArray = [AnyChatPlatform EnumVideoCapture];
    if(cameraDeviceArray.count == 2)
    {
        CurrentCameraDevice = (CurrentCameraDevice+1) % 2;
        [AnyChatPlatform SelectVideoCapture:[cameraDeviceArray objectAtIndex:CurrentCameraDevice]];
    }

}

#pragma mark 隐藏远端UI
- (void)hiddenAllVideoView
{
//    self.iRemoteVideoView1.hidden = YES;
//    self.iRemoteVideoView2.hidden = YES;
//    self.iRemoteVideoView3.hidden = YES;
//    self.iRemoteVideoView4.hidden = YES;
//    self.iRemoteVideoView5.hidden = YES;
//    self.iRemoteVideoView6.hidden = YES;
//    self.iRemoteVideoView7.hidden = YES;
//    self.iRemoteVideoView8.hidden = YES;
//    self.iRemoteVideoView9.hidden = YES;
    for (int i = 0; i < [remoteVideos count]; i++)
    {
        [[remoteVideos objectAtIndex:i] setHidden:YES];
    }

}

#pragma mark 加载音频头像
- (void)loadVoiceHeadImg//后期需从联系人数据库中获取对应用户的头像
{
    for (int i = 0; i < [remoteVideos count]; i++)
    {
        [[remoteVideos objectAtIndex:i] setImage:[UIImage imageNamed:@"defaultHead"]];
    }
}

#pragma mark 1人  UI
- (void)selfChatUI
{
    [self hiddenAllVideoView];
    CGFloat sizeVideo = screenWidth;
    self.theLocalView.frame  = CGRectMake(0, 0, sizeVideo, sizeVideo);

    turnCamera.frame = self.theLocalView.frame;//切换摄像头
    self.localVideoSurface.frame = CGRectMake(0, 0, sizeVideo, sizeVideo);
    [self setVideoBackgroundColorOnNine];

    NSLog(@"2");

}

#pragma mark 2人  UI
- (void)twoUserChatUI
{
    [self hiddenAllVideoView];
    CGFloat sizeVideo = screenWidth/2;

    self.theLocalView.frame      = CGRectMake(0,         80, sizeVideo, sizeVideo);
    self.iRemoteVideoView1.frame = CGRectMake(sizeVideo, 80, sizeVideo, sizeVideo);

    self.iRemoteVideoView1.hidden = NO;
    turnCamera.frame = self.theLocalView.frame;//切换摄像头
    self.localVideoSurface.frame = CGRectMake(0, 0, sizeVideo, sizeVideo);
    [self setVideoBackgroundColorOnNine];
    NSLog(@"2");

}

#pragma mark 3人  UI
- (void)threeUserChatUI
{
    [self hiddenAllVideoView];
    CGFloat sizeVideo = screenWidth/2;

    self.theLocalView.frame      = CGRectMake(0,                           0,         sizeVideo, sizeVideo);
    self.iRemoteVideoView1.frame = CGRectMake(sizeVideo,                   0,         sizeVideo, sizeVideo);
    self.iRemoteVideoView2.frame = CGRectMake(screenWidth/2 - sizeVideo/2, sizeVideo, sizeVideo, sizeVideo);

    self.iRemoteVideoView1.hidden = NO;
    self.iRemoteVideoView2.hidden = NO;
    turnCamera.frame = self.theLocalView.frame;//切换摄像头
    self.localVideoSurface.frame = CGRectMake(0, 0, sizeVideo, sizeVideo);
    [self setVideoBackgroundColorOnNine];
    NSLog(@"3");

}

#pragma mark 4人  UI
- (void)fourUserChatUI
{
    [self hiddenAllVideoView];
    CGFloat sizeVideo = screenWidth/2;

    self.theLocalView.frame      = CGRectMake(0,         0,         sizeVideo, sizeVideo);
    self.iRemoteVideoView1.frame = CGRectMake(sizeVideo, 0,         sizeVideo, sizeVideo);
    self.iRemoteVideoView2.frame = CGRectMake(0,         sizeVideo, sizeVideo, sizeVideo);
    self.iRemoteVideoView3.frame = CGRectMake(sizeVideo, sizeVideo, sizeVideo, sizeVideo);

    self.iRemoteVideoView1.hidden = NO;
    self.iRemoteVideoView2.hidden = NO;
    self.iRemoteVideoView3.hidden = NO;
    turnCamera.frame = self.theLocalView.frame;//切换摄像头
    self.localVideoSurface.frame = CGRectMake(0, 0, sizeVideo, sizeVideo);
    [self setVideoBackgroundColorOnNine];
    NSLog(@"4");

}

#pragma mark 5~9人  UI
- (void)fiveToNineUserChatUI
{
    [self hiddenAllVideoView];
    CGFloat sizeVideo = screenWidth/3;

    self.theLocalView.frame      = CGRectMake(0,             0,             sizeVideo, sizeVideo);
    self.iRemoteVideoView1.frame = CGRectMake(sizeVideo,     0,             sizeVideo, sizeVideo);
    self.iRemoteVideoView2.frame = CGRectMake(sizeVideo * 2, sizeVideo,     sizeVideo, sizeVideo);

    self.iRemoteVideoView3.frame = CGRectMake(0,             sizeVideo,     sizeVideo, sizeVideo);
    self.iRemoteVideoView4.frame = CGRectMake(sizeVideo,     sizeVideo,     sizeVideo, sizeVideo);
    self.iRemoteVideoView5.frame = CGRectMake(sizeVideo * 2, sizeVideo,     sizeVideo, sizeVideo);

    self.iRemoteVideoView6.frame = CGRectMake(0,             sizeVideo * 2, sizeVideo, sizeVideo);
    self.iRemoteVideoView7.frame = CGRectMake(sizeVideo,     sizeVideo * 2, sizeVideo, sizeVideo);
    self.iRemoteVideoView8.frame = CGRectMake(sizeVideo * 2, sizeVideo * 2, sizeVideo, sizeVideo);

    self.iRemoteVideoView1.hidden = NO;
    self.iRemoteVideoView2.hidden = NO;
    self.iRemoteVideoView3.hidden = NO;
    self.iRemoteVideoView4.hidden = NO;
    self.iRemoteVideoView5.hidden = NO;
    self.iRemoteVideoView6.hidden = NO;
    self.iRemoteVideoView7.hidden = NO;
    self.iRemoteVideoView8.hidden = NO;

    turnCamera.frame = self.theLocalView.frame;//切换摄像头
    self.localVideoSurface.frame = CGRectMake(0, 0, sizeVideo, sizeVideo);
    [self setVideoBackgroundColorOnNine];
    NSLog(@"5~9");

}

//- (void)setVideoBackgroundColorOnThree
//{
//    self.theLocalView.backgroundColor      = headBackA;
//    self.iRemoteVideoView1.backgroundColor = headBackB;     //A   B
//    self.iRemoteVideoView2.backgroundColor = headBackC;     //  C
//   
//}
//
//- (void)setVideoBackgroundColorOnFour
//{
//    self.theLocalView.backgroundColor      = headBackA;
//    self.iRemoteVideoView1.backgroundColor = headBackB;     //A  B
//    self.iRemoteVideoView2.backgroundColor = headBackB;     //B  C
//    self.iRemoteVideoView3.backgroundColor = headBackA;
//   
//}

- (void)setVideoBackgroundColorOnNine
{
    self.theLocalView.backgroundColor      = headBackA;
    self.iRemoteVideoView1.backgroundColor = headBackB;     //A  B  C
    self.iRemoteVideoView2.backgroundColor = headBackC;     //B  C  A
    self.iRemoteVideoView3.backgroundColor = headBackB;     //C  A  B
    self.iRemoteVideoView4.backgroundColor = headBackC;
    self.iRemoteVideoView5.backgroundColor = headBackA;
    self.iRemoteVideoView6.backgroundColor = headBackC;
    self.iRemoteVideoView7.backgroundColor = headBackA;
    self.iRemoteVideoView8.backgroundColor = headBackB;

}


- (void)delayCheckCuDeviceIsSupportVideoChat
{
    [self checkCuDeviceIsSupportVideoChat];

}

- (BOOL)checkCuDeviceIsSupportVideoChat//微信上不支持 iPhone4 的视频聊天 也许是因为4视频的时候很卡的原因
{
    NSString *cuDeviceStr =  [Tools getCurrentDeviceModel];

    if ([cuDeviceStr isEqualToString:@"iPhone 4 (A1332)"] |
        [cuDeviceStr isEqualToString:@"iPhone 4 (A1332)"] |
        [cuDeviceStr isEqualToString:@"iPhone 4 (A1349)"] |
        [cuDeviceStr isEqualToString:@"iPhone 4S (A1387/A1431)"]){

        [self showAlertCuDeviceNoSupportVideoChat];
        return NO;
    }

    return YES;

}

#pragma mark 当前设备不能使用视频功能
- (void)showAlertCuDeviceNoSupportVideoChat
{
    UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"当前设备不能使用视频功能。"
                                                  message:@""
                                                 delegate:self
                                        cancelButtonTitle:@"我知道了"
                                        otherButtonTitles:nil,
                         nil];
    [alert show];

}

#pragma mark 轻触切换摄像头
- (void)showTipsHowToTurnCamera
{

    UILabel *label = [[UILabel alloc] init];
    label.text = @"轻触切换摄像头";
    label.font = [UIFont systemFontOfSize:14];
    label.textAlignment = NSTextAlignmentCenter;//内容居中
    label.textColor = [UIColor whiteColor];
    label.backgroundColor = [UIColor blackColor];
    label.frame = self.theLocalView.frame;
    label.alpha = 0.0;//这里将透明度设置为完全透明,是为了让它在之后渐渐显示出来。
    [self.view addSubview:label];


    //动画
    [UIView animateWithDuration:1.0 animations:^{
        label.alpha = 0.5;

    } completion:^(BOOL finished)
     {
         [UIView animateWithDuration:1.0 delay:1.5 options:UIViewAnimationOptionCurveLinear animations:^{

             label.alpha = 0.0;

         } completion:^(BOOL finished)
          {

              [label removeFromSuperview];//将label从控制器中移除【也从内存中释放了】

          }];
     }];

}

#pragma mark [添加]好友聊天
- (void)addFriendsChat
{
    //1.跳转到邀请列表界面[可多选]
    //2.点击邀请界面的确定按钮后,向指定好友发送邀请[邀请前 验证合法性:总人数不超过9人]
    //3.被邀请人员 在进入聊天室之前需要验证 当前房间人数的合法性 如果包括自己 人数超过9人 则不允许进入 并给出提示
    NSLog(@"添加好友进入聊天");

}

#pragma mark [开关]静音
- (void)jingYinPress
{
    if (isJingYin == NO)//关闭
    {
        isJingYin = YES;
        imgJingYin.image = [UIImage imageNamed:@"multitalkMuteModeOn"];
        [AnyChatPlatform UserSpeakControl:-1:NO];
//        NSLog(@"——————————————————————————————————————————————————————————————————————————————————关闭----本地麦克风");
    }
    else//打开
    {
        isJingYin = NO;
        imgJingYin.image = [UIImage imageNamed:@"multitalkMuteMode"];
        [AnyChatPlatform UserSpeakControl:-1:YES];
//        NSLog(@"——————————————————————————————————————————————————————————————————————————————————打开----本地麦克风");
    }

}

#pragma mark [开关]免提
- (void)mianTiSwitch
{
    if (speaker == nil)
    {
        NSMutableArray *EnumAudioArr = [AnyChatPlatform EnumAudioPlayback];
        NSLog(@"AudioPlayback %@", EnumAudioArr);
        speaker = [EnumAudioArr objectAtIndex:0];
        receiver = [EnumAudioArr objectAtIndex:1];

    }
    if (!isHandFree)
    {
        [AnyChatPlatform SelectAudioPlayback:speaker];//设置免提模式
        NSLog(@"打开:%@", speaker);
        isHandFree = YES;
        imgHands.image = [UIImage imageNamed:@"multitalkSpeakerModeOn"];

    }
    else
    {
        [AnyChatPlatform SelectAudioPlayback:receiver];//设置听筒模式
        NSLog(@"打开:%@", receiver);
        isHandFree = NO;
        imgHands.image = [UIImage imageNamed:@"multitalkSpeakerMode"];

    }

}

#pragma mark [开关]视频
- (void)localVideoSwitch
{
    if ([self checkCuDeviceIsSupportVideoChat])
    {
        if (!isOnlyOnce)
        {
            isOnlyOnce = YES;
            [self showTipsHowToTurnCamera];
            [self StartLocalVideoChat];

        }

        if ([AnyChatPlatform GetCameraState:-1] == 1)
        {
            //open local Camera
            [AnyChatPlatform SetVideoPos:-1 :self :0 :0 :0 :0];
            [AnyChatPlatform UserCameraControl:-1 : YES];
            self.theLocalView.hidden = NO;
            imgVideoSwitch.image = [UIImage imageNamed:@"multitalkVideoOn"];

        }

        if ([AnyChatPlatform GetCameraState:-1] == 2)
        {
            //close local Camera
            [AnyChatPlatform UserCameraControl:-1 :NO];
            self.theLocalView.hidden = YES;
            imgVideoSwitch.image = [UIImage imageNamed:@"multitalkVideo"];

        }

    }

}

#pragma mark [挂断]
- (void)hangUp
{
    NSLog(@"通话时长为:%@",labTimer.text);
    [self FinishVideoChat];
    //获取根控制器,和当前的做个比较
    AppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
    UIViewController *rootVC = appDelegate.window.rootViewController;
    if (self == rootVC)
    {
        ViewController *vc = [[ViewController alloc]init];
        [self presentViewController:vc animated:YES completion:nil];

    }
    else
    {
        [self dismissViewControllerAnimated:YES completion:nil];

    }

    isCuVideoVC = NO;

}

- (void)hangUpDown
{
    imgHangUp.image = [UIImage imageNamed:@"callDeclineBtnHL"];

}

- (void)hangUpUp
{
    imgHangUp.image = [UIImage imageNamed:@"callDeclineBtn"];

}

#pragma mark 打开本地麦克风
- (void)openLocalMicrophone
{
    [AnyChatPlatform UserSpeakControl: -1:YES];

}

#pragma mark 开启本地视频
- (void) StartLocalVideoChat
{
    //Get a camera, Must be in the real machine.
    NSMutableArray* cameraDeviceArray = [AnyChatPlatform EnumVideoCapture];//枚举出设备
    if (cameraDeviceArray.count > 0)
    {
        [AnyChatPlatform SelectVideoCapture:[cameraDeviceArray objectAtIndex:1]];//使用枚举出来的设备
    }

    // open local video
    [AnyChatPlatform SetSDKOptionInt:BRAC_SO_LOCALVIDEO_OVERLAY :1];
//    [AnyChatPlatform UserSpeakControl: -1:YES];
    [AnyChatPlatform SetVideoPos:-1 :self :0 :0 :0 :0];
    [AnyChatPlatform UserCameraControl:-1 : YES];

//    [AnyChatPlatform SetSDKOptionInt:BRAC_SO_NETWORK_AUTORECONNECT :1];// 网络掉线自动重连功能控制
    [AnyChatPlatform SetSDKOptionInt:BRAC_SO_LOCALVIDEO_ORIENTATION : self.interfaceOrientation];

}

#pragma mark 绘制本地视频
- (void) OnLocalVideoInitid)session
{
    self.localVideoSurface              = [AVCaptureVideoPreviewLayer layerWithSession: (AVCaptureSession*)session];
    self.localVideoSurface.frame        = CGRectMake(0, 0, self.theLocalView.frame.size.width, self.theLocalView.frame.size.height);
    self.localVideoSurface.videoGravity = AVLayerVideoGravityResizeAspectFill;

    [self.theLocalView.layer addSublayer:self.localVideoSurface];
    [self.view addSubview:turnCamera];
    NSLog(@"—————————————————————#pragma mark 绘制本地视频—————————————————————————————————————————————");

}

#pragma mark - Instance Method 远端视频
- (void) myEnterRoomChat//[遍历聊天室中所有的人(自己除外)]
{
    NSMutableArray *onlineUserMArray = [[ViewController getSelfIsSingleObj] getOnlineUserArray];

    //获取循环的最大次数
    int forCount = 0;
    int uArrayCount = (int)onlineUserMArray.count;
    uArrayCount > 8 ? (forCount = 8) : (forCount = uArrayCount);//kVideoWindowNumInt = 8个人
    if (uArrayCount == 0)
    {
        [self selfChatUI];
    }
    if (uArrayCount == 1)
    {
        [self twoUserChatUI];
    }
    if (uArrayCount == 2)
    {
        [self threeUserChatUI];
    }
    if (uArrayCount == 3)
    {
        [self fourUserChatUI];
    }
    if (uArrayCount > 3 && uArrayCount <= 8)
    {
        [self fiveToNineUserChatUI];
    }
    NSLog(@"———————VideoVC——————————————————————myEnterRoomChat—————————————————当前房间里除了我有%d个人", uArrayCount);
    if (uArrayCount > 0)
    {
        for (int i = 0; i < forCount; i++)
        {
            int iRemoteUserID = [[onlineUserMArray objectAtIndex:i] intValue];
            [self StartTargerVideoChatWithID:iRemoteUserID Tagi+1)];

            //记录已经视频的userID到theTargetUserIDStrMArray[用于重连?]
            [[ViewController getSelfIsSingleObj].theOnChatUserIDStrMArray replaceObjectAtIndex:i
                                                                            withObject:[[NSString alloc] initWithFormat:@"%d",iRemoteUserID]];
        }
    }

}

//初始化远端视频
- (void) StartTargerVideoChatWithIDint)targerUserID Tagint)tag
{

    NSString *userName = [AnyChatPlatform GetUserName:targerUserID];

    // request other user video
    [AnyChatPlatform UserSpeakControl: targerUserID:YES];
    switch (tag)
    {
        case 1 :
        {
            [AnyChatPlatform SetVideoPos:targerUserID: self.iRemoteVideoView1:0:0:0:0];
            self.iRemoteVideoView1.tag = targerUserID;//用于当远端视频关闭时 为其设置背景头像
//            self.iRemoteVideoView1.contentMode = UIViewContentModeScaleAspectFit;
            break;
        }

        case 2 :
        {
            [AnyChatPlatform SetVideoPos:targerUserID: self.iRemoteVideoView2:0:0:0:0];
            self.iRemoteVideoView2.tag = targerUserID;
            break;
        }

        case 3 :
        {
            [AnyChatPlatform SetVideoPos:targerUserID: self.iRemoteVideoView3:0:0:0:0];
            self.iRemoteVideoView3.tag = targerUserID;
            break;
        }
        case 4 :
        {
            [AnyChatPlatform SetVideoPos:targerUserID: self.iRemoteVideoView4:0:0:0:0];
            self.iRemoteVideoView4.tag = targerUserID;
            break;
        }
        case 5 :
        {
            [AnyChatPlatform SetVideoPos:targerUserID: self.iRemoteVideoView5:0:0:0:0];
            self.iRemoteVideoView5.tag = targerUserID;
            break;
        }
        case 6 :
        {
            [AnyChatPlatform SetVideoPos:targerUserID: self.iRemoteVideoView6:0:0:0:0];
            self.iRemoteVideoView6.tag = targerUserID;
            break;
        }
        case 7 :
        {
            [AnyChatPlatform SetVideoPos:targerUserID: self.iRemoteVideoView7:0:0:0:0];
            self.iRemoteVideoView7.tag = targerUserID;
            break;
        }
        case 8 :
        {
            [AnyChatPlatform SetVideoPos:targerUserID: self.iRemoteVideoView8:0:0:0:0];
            self.iRemoteVideoView8.tag = targerUserID;
            break;
        }

    }

    [AnyChatPlatform UserCameraControl:targerUserID : YES];
    [AnyChatPlatform SetSDKOptionInt:BRAC_SO_LOCALVIDEO_ORIENTATION : self.interfaceOrientation];

}


#pragma mark 视频旋转【当远端旋转视频时 回调】
- (void)willAnimateRotationToInterfaceOrientationUIInterfaceOrientation)toInterfaceOrientation durationNSTimeInterval)duration
{
    //device orientation
    UIDeviceOrientation devOrientation = [UIDevice currentDevice].orientation;

    if (devOrientation == UIDeviceOrientationLandscapeLeft)
    {
        [self setFrameOfLandscapeLeft];
    }
    else if (devOrientation == UIDeviceOrientationLandscapeRight)
    {
        [self setFrameOfLandscapeRight];
    }
    if (devOrientation == UIDeviceOrientationPortrait)
    {
        [self setFrameOfPortrait];
    }

}


#pragma mark - Video Rotation
-(void)setFrameOfPortrait
{

}

-(void)setFrameOfLandscapeLeft
{

}

-(void)setFrameOfLandscapeRight
{

}

- (void) FinishVideoChat
{
    [AnyChatPlatform UserSpeakControl: -1 : NO];
    [AnyChatPlatform UserCameraControl: -1 : NO];

    //释放远端所有用户的 麦克风 和 视频 资源
    for (NSString *uID in [ViewController getSelfIsSingleObj].theOnChatUserIDStrMArray )
    {
        int userId = [uID intValue];
        if (userId != 0 )
        {
            [AnyChatPlatform UserSpeakControl : userId : NO];
            [AnyChatPlatform UserCameraControl: userId : NO];
        }
    }

    [AnyChatPlatform LeaveRoom:-1];

}

#pragma mark 释放资源[本地视频]
- (void) OnLocalVideoReleaseid)sender
{
    if(self.localVideoSurface)
    {
        self.localVideoSurface = nil;
        NSLog(@"—————————————————————#pragma mark 释放资源[本地视频]—————————————————————————————————————————————");
    }

}

#pragma mark 设置远端语音头像
- (void) setRemoteUIBackgroundWithIdint)userId andState:(int)state
{
    NSLog(@"远端摄像头状态改变 userid : %d, state : %d", userId, state);
    //userId 要与 iRemoteVideoViewX 对应
    //state 1:关闭摄像头 2:打开摄像头
    for (int i = 0; i < [remoteVideos count]; i++)
    {
        if (userId == [[remoteVideos objectAtIndex:i] tag])
        {
            if (state == 1)//后期需从联系人数据库中获取对应用户的头像
            {
                [[remoteVideos objectAtIndex:i] setImage:[UIImage imageNamed:@"defaultHead"]];
            }
        }
    }

}

//隐藏状态栏
- (BOOL)prefersStatusBarHidden
{
    return YES;

}

- (void)dealloc
{
    imgJingYin              = nil;
    imgHands                = nil;
    imgVideoSwitch          = nil;
    imgHangUp               = nil;
    imgAddFriends           = nil;
    turnCamera              = nil;
    ctrlAddFriends          = nil;
    containUp               = nil;
    MZTtime                 = nil;
    labTimer                = nil;
    ctrlHangUp              = nil;
    ctrljingYin             = nil;
    ctrlVideo               = nil;
    ctrlMianTi              = nil;
    speaker                 = nil;
    receiver                = nil;

    self.theLocalView       = nil;
    self.localVideoSurface  = nil;
    self.iRemoteVideoView1  = nil;
    self.iRemoteVideoView2  = nil;
    self.iRemoteVideoView3  = nil;
    self.iRemoteVideoView4  = nil;
    self.iRemoteVideoView5  = nil;
    self.iRemoteVideoView6  = nil;
    self.iRemoteVideoView7  = nil;
    self.iRemoteVideoView8  = nil;
    self.iRemoteVideoView9  = nil;

}
@end


分享到:  QQ好友和群QQ好友和群 QQ空间QQ空间 腾讯微博腾讯微博 腾讯朋友腾讯朋友
收藏收藏
回复

使用道具 举报

14

主题

87

帖子

258

积分

中级会员

Rank: 3Rank: 3

积分
258
沙发
 楼主| 发表于 2016-3-3 10:34:46 | 只看该作者
肿么没有人回答我的问题。。。。
回复 支持 反对

使用道具 举报

14

主题

87

帖子

258

积分

中级会员

Rank: 3Rank: 3

积分
258
板凳
 楼主| 发表于 2016-3-3 14:52:34 | 只看该作者
我的问题已经得到了解决。 不过方法不是清楚之前UIView上layer上渲染的图像,而是在这个之上再渲染一层新的UIView的layer,用这个方式来覆盖掉之前的layer。
代码如下:
//覆盖掉关闭视频时停留在theLocalView上的最后一帧的图像

代码如下:
//覆盖掉关闭视频时停留在theLocalView上的最后一帧的图像
            UIView *back = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.theLocalView.frame.size.width, self.theLocalView.frame.size.height)];
            back.backgroundColor = backColor;
            [self.theLocalView.layer addSublayer:back.layer];
            back = nil;
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

Archiver|手机版|AnyChat ( 粤ICP备13022410号-1 )  

GMT+8, 2024-11-22 22:59 , Processed in 0.130756 second(s), 24 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表