设为首页收藏本站

AnyChat技术支持论坛

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
热搜: 活动 交友 discuz
楼主: kenshin
打印 上一主题 下一主题

视频如何等比例显示

[复制链接]

5

主题

180

帖子

801

积分

高级会员

Rank: 4

积分
801
21#
发表于 2016-2-1 13:49:04 | 只看该作者
kenshin 发表于 2016-2-1 13:33
你好,为什么我调用了才裁剪视频的接口后 我的视频显示并没有发生裁剪变化呢?
if (flagTimes == 1)
   ...

您好,请问你的SDK是什么版本?把日志发出来,在程序运行目录下(.log文件)
回复 支持 1 反对 0

使用道具 举报

1

主题

16

帖子

162

积分

注册会员

Rank: 2

积分
162
22#
发表于 2016-2-1 14:02:01 | 只看该作者
kenshin 发表于 2016-2-1 13:33
你好,为什么我调用了才裁剪视频的接口后 我的视频显示并没有发生裁剪变化呢?
if (flagTimes == 1)
   ...

您好,你或者可以尝试下修改imageview控件的contentmode属性来达到裁剪效果,contentmode属性参考网址:http://blog.csdn.net/huifeidexin_1/article/details/8524507
回复 支持 反对

使用道具 举报

14

主题

87

帖子

258

积分

中级会员

Rank: 3Rank: 3

积分
258
23#
 楼主| 发表于 2016-2-1 14:15:26 | 只看该作者
tjt_223 发表于 2016-2-1 14:02
您好,你或者可以尝试下修改imageview控件的contentmode属性来达到裁剪效果,contentmode属性参考网址:h ...

谢谢,直接改变图片的显示形式就解决了。thank you!
回复 支持 反对

使用道具 举报

14

主题

87

帖子

258

积分

中级会员

Rank: 3Rank: 3

积分
258
24#
 楼主| 发表于 2016-2-1 14:21:05 | 只看该作者
佰锐科技-李永星 发表于 2016-2-1 13:49
您好,请问你的SDK是什么版本?把日志发出来,在程序运行目录下(.log文件)

我的SDK是目前官网最新的 谢谢了
我的问题已经解决了;
我修改了imageview控件的contentmode属性;
回复 支持 反对

使用道具 举报

14

主题

87

帖子

258

积分

中级会员

Rank: 3Rank: 3

积分
258
25#
 楼主| 发表于 2016-2-2 15:59:24 | 只看该作者
tjt_223 发表于 2016-2-1 14:02
您好,你或者可以尝试下修改imageview控件的contentmode属性来达到裁剪效果,contentmode属性参考网址:h ...

你好,我的视频原料demo中两端都收不到语音。不知道是怎么回事。我的音频聊天和视频聊天是分成两个控制器写的,音频聊天有声音,视频聊天没有声音。
关键的代码应该是下面这部分吧?
// open local video[执行这段代码之后 会调用 OnLocalVideoInit[进行摄像头的初始化]]
    [AnyChatPlatform SetSDKOptionInt:BRAC_SO_LOCALVIDEO_OVERLAY :1];
    [AnyChatPlatform UserSpeakControl: -1:YES];//打开本地麦克风
    [AnyChatPlatform SetVideoPos:-1 :self :0 :0 :0 :0];
    [AnyChatPlatform UserCameraControl:-1 : YES];

    // request other user video
    [AnyChatPlatform UserSpeakControl: userid:YES];
    [AnyChatPlatform SetVideoPos:userid: self.theUIImageView:0:0:0:0];
    [AnyChatPlatform UserCameraControl:userid : YES];



回复 支持 反对

使用道具 举报

26#
发表于 2016-2-2 16:05:24 | 只看该作者
kenshin 发表于 2016-2-2 15:59
你好,我的视频原料demo中两端都收不到语音。不知道是怎么回事。我的音频聊天和视频聊天是分成两个控制器 ...

请将双方的日志发上来分析,谢谢!
回复 支持 反对

使用道具 举报

14

主题

87

帖子

258

积分

中级会员

Rank: 3Rank: 3

积分
258
27#
 楼主| 发表于 2016-2-2 16:20:45 | 只看该作者
佰锐科技-邵光清 发表于 2016-2-2 16:05
请将双方的日志发上来分析,谢谢!

【音频】正常
2016-02-02 16:16:05.687 PartyConstructionSystem[1517:254335] 接受了对方的聊天请求, 聊天类型为: voice_request
2016-02-02 16:16:05.688 PartyConstructionSystem[1517:254335] Invoke        Connect(117.135.239.160,8906)=0
2016-02-02 16:16:05.689 PartyConstructionSystem[1517:254335] Invoke        EnterRoom(roomid=4)
2016-02-02 16:16:05.691 PartyConstructionSystem[1517:255340] sendstring ["audio_chat","1407","bc78933e6dce542e7f8c599786d7ba35","[4]","voice_receive"] 2016-02-02 16:16:05.930 PartyConstructionSystem[1517:255340] 下载数据:110-----+ 2016-02-02 16:16:05.931 PartyConstructionSystem[1517:255340] stream close!
2016-02-02 16:16:07.459 PartyConstructionSystem[1517:254442] Message        OnUserEnterRoom(userid=-1018,nickname=1454400964870,siteindex=1)
2016-02-02 16:16:07.471 PartyConstructionSystem[1517:254335] vvvvvvvvvvvvvvvv------chatType == (null), bfjChatType == voice_request, fromId == 4, userId == 1407
2016-02-02 16:16:07.493 PartyConstructionSystem[1517:254335] Invoke        UserSpeakControl(userid=-1018,bOpen=1)
2016-02-02 16:16:07.774 PartyConstructionSystem[1517:254442] On Remote UserCameraControl(dwUserId:-1018, bOpen:1)
2016-02-02 16:16:07.807 PartyConstructionSystem[1517:254442] On Remote UserSpeakControl(dwUserId:-1018, bOpen:1)
2016-02-02 16:16:08.089 PartyConstructionSystem[1517:254442] Message        OnP2PConnectState(userid=-1018, state=1)
2016-02-02 16:16:08.262 PartyConstructionSystem[1517:254335] Invoke        UserSpeakControl(userid=-1,bOpen=1)
2016-02-02 16:16:08.263 PartyConstructionSystem[1517:254335] Audio record control:1, result:-1
2016-02-02 16:16:08.306 PartyConstructionSystem[1517:254447] Default Audio Capture Driver()
2016-02-02 16:16:08.307 PartyConstructionSystem[1517:254447] Audio Init, error:0, device:0, 1, 16000, 16, capmode:0
2016-02-02 16:16:08.309 PartyConstructionSystem[1517:254447] Audio codec init, handle:1, 11, 1, 16000, 16, 15850
2016-02-02 16:16:08.313 PartyConstructionSystem[1517:254442] Message        OnP2PConnectState(userid=-1018, state=3)
2016-02-02 16:16:08.355 PartyConstructionSystem[1517:254802] userid(-1018) audio decode, codec:11, 1 channel, 16000Hz
2016-02-02 16:16:08.429 PartyConstructionSystem[1517:254600] Audio FX Status: VAD:1, NS:1, AGC:1, AEC:1

【视频】无音频
2016-02-02 16:18:19.955 PartyConstructionSystem[1517:254335] 接受了对方的聊天请求, 聊天类型为: video_request
2016-02-02 16:18:19.956 PartyConstructionSystem[1517:254335] Invoke        Connect(117.135.239.160,8906)=0
2016-02-02 16:18:19.957 PartyConstructionSystem[1517:254335] Invoke        EnterRoom(roomid=4)
2016-02-02 16:18:19.960 PartyConstructionSystem[1517:255792] sendstring ["audio_chat","1407","bc78933e6dce542e7f8c599786d7ba35","[4]","voice_receive"] 2016-02-02 16:18:20.004 PartyConstructionSystem[1517:254442] Message        OnEnterRoom(roomid=4,errorcode=0,siteindex=0)
2016-02-02 16:18:20.031 PartyConstructionSystem[1517:254442] Audio Playback Device Init(0, 1, 16000, 16), ios Playback Driver
2016-02-02 16:18:20.033 PartyConstructionSystem[1517:254442] Message        OnReceiveOnlineUser(count=1,roomid=4)
2016-02-02 16:18:20.044 PartyConstructionSystem[1517:254335] ----------------------用户进入的 房间id号:4----------------------
2016-02-02 16:18:20.045 PartyConstructionSystem[1517:254335] dwUserNum == 1
2016-02-02 16:18:20.046 PartyConstructionSystem[1517:254335] >>>>>>>>>>>>>>>>>>>>>>>>>1>>>>>>>>>>>>>>>>>>>>>>>>>除了我,没有人在房间里
2016-02-02 16:18:20.087 PartyConstructionSystem[1517:255792] 下载数据:110-----+ 2016-02-02 16:18:20.088 PartyConstructionSystem[1517:255792] stream close!
2016-02-02 16:18:21.487 PartyConstructionSystem[1517:254442] Message        OnUserEnterRoom(userid=-1019,nickname=1454401098961,siteindex=1)
2016-02-02 16:18:21.494 PartyConstructionSystem[1517:254335] vvvvvvvvvvvvvvvv------chatType == (null), bfjChatType == video_request, fromId == 4, userId == 1407
2016-02-02 16:18:21.496 PartyConstructionSystem[1517:254335] Invoke        UserSpeakControl(userid=-1,bOpen=1)
2016-02-02 16:18:21.497 PartyConstructionSystem[1517:254335] Audio record control:1, result:-1
2016-02-02 16:18:21.497 PartyConstructionSystem[1517:254335] Invoke        SetVideoPos(dwUserId:-1, hWnd:0x1828a00, l:0, t:0, r:0, b:0)
2016-02-02 16:18:21.498 PartyConstructionSystem[1517:254335] Invoke        UserCameraControl(userid=-1, bOpen=1, stream=0)
2016-02-02 16:18:21.499 PartyConstructionSystem[1517:254335] Invoke        UserSpeakControl(userid=-1019,bOpen=1)
2016-02-02 16:18:21.500 PartyConstructionSystem[1517:254335] Invoke        SetVideoPos(dwUserId:-1019, hWnd:0xcc1e350, l:0, t:0, r:0, b:0)
2016-02-02 16:18:21.501 PartyConstructionSystem[1517:254335] Invoke        UserCameraControl(userid=-1019, bOpen=1, stream=0)
2016-02-02 16:18:21.504 PartyConstructionSystem[1517:254335] Invoke        UserSpeakControl(userid=-1,bOpen=1)
2016-02-02 16:18:21.521 PartyConstructionSystem[1517:254447] Default Audio Capture Driver()

2016-02-02 16:18:21.531 PartyConstructionSystem[1517:254335] Audio record control:1, result:-50
2016-02-02 16:18:21.532 PartyConstructionSystem[1517:254335] Invoke        SetVideoPos(dwUserId:-1, hWnd:0x1828a00, l:0, t:0, r:0, b:0)
2016-02-02 16:18:21.533 PartyConstructionSystem[1517:254335] Invoke        UserCameraControl(userid=-1, bOpen=1, stream=0)
2016-02-02 16:18:21.534 PartyConstructionSystem[1517:254335] Invoke        UserSpeakControl(userid=-1019,bOpen=1)
2016-02-02 16:18:21.535 PartyConstructionSystem[1517:254335] Invoke        SetVideoPos(dwUserId:-1019, hWnd:0x92f0e30, l:0, t:0, r:0, b:0)
2016-02-02 16:18:21.539 PartyConstructionSystem[1517:254335] Invoke        UserCameraControl(userid=-1019, bOpen=1, stream=0)
2016-02-02 16:18:21.537 PartyConstructionSystem[1517:254447] Audio Init, error:0, device:0, 1, 16000, 16, capmode:0
2016-02-02 16:18:21.558 PartyConstructionSystem[1517:254447] Audio codec init, handle:3, 11, 1, 16000, 16, 15850
2016-02-02 16:18:21.581 PartyConstructionSystem[1517:254335] Invoke        UserCameraControl(userid=-1, bOpen=0, stream=0)
2016-02-02 16:18:21.581 PartyConstructionSystem[1517:254335] Invoke        SetVideoPos(dwUserId:-1, hWnd:0x1828a00, l:0, t:0, r:0, b:0)
2016-02-02 16:18:21.582 PartyConstructionSystem[1517:254335] Invoke        UserCameraControl(userid=-1, bOpen=1, stream=0)
2016-02-02 16:18:21.583 PartyConstructionSystem[1517:254335] Invoke        UserSpeakControl(userid=-1,bOpen=1)
2016-02-02 16:18:21.580 PartyConstructionSystem[1517:254447] Audio record control:1, result:-50
2016-02-02 16:18:21.594 PartyConstructionSystem[1517:254335] Audio record control:1, result:-50
2016-02-02 16:18:21.596 PartyConstructionSystem[1517:254335] Invoke        UserSpeakControl(userid=-1,bOpen=1)
2016-02-02 16:18:21.604 PartyConstructionSystem[1517:254335] Audio record control:1, result:-50
2016-02-02 16:18:21.625 PartyConstructionSystem[1517:254442] Message        OnP2PConnectState(userid=-1019, state=1)
2016-02-02 16:18:21.727 PartyConstructionSystem[1517:254447] WARNING: -[<AVCaptureConnection: 0x9f93800> isVideoMinFrameDurationSupported] is deprecated.  Please use AVCaptureDevice activeFormat.videoSupportedFrameRateRanges
2016-02-02 16:18:21.728 PartyConstructionSystem[1517:254447] WARNING: -[<AVCaptureConnection: 0x9f93800> setVideoMinFrameDuration:] is deprecated.  Please use AVCaptureDevice setActiveVideoMinFrameDuration
2016-02-02 16:18:21.960 PartyConstructionSystem[1517:254442] Message        OnP2PConnectState(userid=-1019, state=3)
2016-02-02 16:18:22.355 PartyConstructionSystem[1517:254447] video init finish: 640x480, 25fps, fmt:100, ret:0
2016-02-02 16:18:22.356 PartyConstructionSystem[1517:254447] video init finish:640x480, YUV420, fps:25, codecid:1
[libx264 @ 0x1b1ee10] using cpu capabilities: ARMv6 NEON
2016-02-02 16:18:22.412 PartyConstructionSystem[1517:254442] On Remote UserCameraControl(dwUserId:-1019, bOpen:1)
2016-02-02 16:18:22.426 PartyConstructionSystem[1517:254442] On Remote UserSpeakControl(dwUserId:-1019, bOpen:1)
[libx264 @ 0x1b1ee10] profile High, level 2.2
2016-02-02 16:18:22.439 PartyConstructionSystem[1517:255707] video codec init:codec:1, 15fps, 640x480, bitrate:360kbps, quality:3, preset:3, gop:30, handle:4
2016-02-02 16:18:22.484 PartyConstructionSystem[1517:254802] userid(-1019) audio decode, codec:11, 1 channel, 16000Hz
2016-02-02 16:18:22.689 PartyConstructionSystem[1517:254803] userid(-1019) video decode, codec:1, 640x480, delay:23ms

回复 支持 反对

使用道具 举报

28#
发表于 2016-2-2 16:49:59 | 只看该作者
kenshin 发表于 2016-2-2 16:20
【音频】正常
2016-02-02 16:16:05.687 PartyConstructionSystem[1517:254335] 接受了对方的聊天请求,  ...

您好,从日志上分析是正常。请问,先进行视频聊天,再转到音频聊天,是否正常呢?
回复 支持 反对

使用道具 举报

14

主题

87

帖子

258

积分

中级会员

Rank: 3Rank: 3

积分
258
29#
 楼主| 发表于 2016-2-2 16:57:18 | 只看该作者

我的代码

本帖最后由 kenshin 于 2016-2-2 16:59 编辑


佰锐科技-邵光清 发表于 2016-2-2 16:49
您好,从日志上分析是正常。请问,先进行视频聊天,再转到音频聊天,是否正常呢?

你好,音频聊天没有问题,只是进入视频聊天的时候两端收不到声音,切换的时候也是一样

//
//  PartyConstructionSystem
//
//  Created by kenshin2 on 15/12/24.
//  Copyright © 2015年 李狗蛋. All rights reserved.
//

#import "VideoChatVC.h"
#import "MZTimerLabel.h"
#import "SendStream.h"
#import "VoiceChatVC.h"
#import "AudioToolbox/AudioToolbox.h"
#import "AnyChatDefine.h"

@interface VideoChatVC ()
{
    CGFloat             screenWidth;
    CGFloat             screenHeight;
    BOOL                isFullScreen;

    UIControl           *ctrlSwitchFullScreen;
    //顶部
    UILabel             *timeLab;
    UIControl           *turnModelCtrl;
    //底部
    UIView              *containBottomCtrls;
    UIControl           *ctrlTurnLocalVideo;
    UIControl           *ctrlSwitchVideo;
    UIControl           *ctrlSwitchVoice;
    UIControl           *ctrlHangUp;

    //底部按钮的图片
    UIImageView         *imgV1;
    UIImageView         *imgV2;
    UIImageView         *imgV3;
    UIImageView         *imgV4;

    UIImageView         *changeChatModeView;
    //切换按钮图片的标志
    BOOL                flag1;
    BOOL                flag2;
    BOOL                flag3;
    BOOL                flag4;

    //用于切换聊天模式
    int                 remoteUserid;
    BOOL                isOnce;//关于 voice_close 的通知有两处,一种是对方挂断,另一种是对方离开房间
    int                 flagTimes;
}

@end

@implementation VideoChatVC

//单例
+ (VideoChatVC *)getSelfIsSingleObj
{
    static VideoChatVC *sharedAccountManagerInstance = nil;
    static dispatch_once_t predicate;
    dispatch_once(&predicate, ^{
        sharedAccountManagerInstance = [[VideoChatVC alloc] init];
    });

    return sharedAccountManagerInstance;
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    screenWidth  = [[UIScreen mainScreen] bounds].size.width;
    screenHeight = [[UIScreen mainScreen] bounds].size.height;

    //正在聊天时,收到对方挂断聊天的通知 from MyMsgViewController
    [[NSNotificationCenter defaultCenter] addObserver:self selectorselector(remoteChatClose) name"voice_close" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selectorselector(remoteVideoPause) name"video_pause" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selectorselector(remoteVideoContinue) name"video_continue" object:nil];
    [[NSNotificationCenter defaultCenter] addObserver:self selectorselector(remoteTurnVoiceChat) name"voice_reject" object:nil];

    //收到了对方切换至语音聊天界面的通知
    [[NSNotificationCenter defaultCenter] addObserver:self selectorselector(remoteTurnVoiceChat) name"video_reject" object:nil];

    self.closeCameraHintView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
    UIImageView *back = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
    back.image = [UIImage imageNamed"voice_chat_back"];

    UILabel *hintLb = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, screenWidth, 30)];
    hintLb.center = CGPointMake(screenWidth/2, screenHeight/2);
    hintLb.text = @"对方已关闭摄像头";
    hintLb.textColor = [UIColor whiteColor];
    hintLb.font = [UIFont systemFontOfSize:20];
    hintLb.textAlignment = NSTextAlignmentCenter;
    [self.closeCameraHintView addSubview:back];
    [self.closeCameraHintView addSubview:hintLb];

}

- (void)test//让远端视频等比例显示[设置 UIImageView 的显示模式]
{
    /*
     // 视频裁剪模式定义
     #define ANYCHAT_VIDEOCLIPMODE_AUTO                        0        ///< 默认模式,以最大比例进行裁剪,然后再整体拉伸,画面保持比例,但被裁剪画面较大
     #define ANYCHAT_VIDEOCLIPMODE_OVERLAP                1        ///< 重叠模式,只取最大有效部分,对边缘进行裁剪
     #define ANYCHAT_VIDEOCLIPMODE_SHRINK                2        ///< 缩小模式,缩小到合适的比例,不进行裁剪
     #define ANYCHAT_VIDEOCLIPMODE_STRETCH                3        ///< 平铺模式,不进行裁剪,但可能导致画面不成比例
     #define ANYCHAT_VIDEOCLIPMODE_DYNAMIC                4        ///< 动态模式,由上层应用根据分辩率来调整显示表面,保持画面不变形
     */

    //获取远端视频画面比例
    int width = [AnyChatPlatform GetUserVideoWidth:remoteUserid];
    int height = [AnyChatPlatform GetUserVideoHeight:remoteUserid];

    //    NSString *test = [AnyChatPlatform QueryUserStateString:userid :BRAC_USERSTATE_VIDEOSIZE];
    NSLog(@"###############################对方视频的宽高分辨是:%d, %d", width, height);
    //常规的做法是:显示视频时,通过API接口(QuerUserState)获取对方的视频大小(宽度、高度),然后控制显示窗口(Surface)的大小,使显示窗口的大小与原始视频的大小成比例,就不会被拉伸了。
    //参考
//    BRAC_SetSDKOption(BRAC_SO_RECORD_CLIPMODE, ANYCHAT_VIDEOCLIPMODE_DYNAMIC);
    if (flagTimes == 1)
    {
//        [AnyChatPlatform SetSDKOptionInt:BRAC_SO_VIDEOSHOW_CLIPMODE:ANYCHAT_VIDEOCLIPMODE_AUTO];
        self.theUIImageView.contentMode = UIViewContentModeScaleAspectFill;
    }
    if (flagTimes == 2)
    {
//        [AnyChatPlatform SetSDKOptionInt:BRAC_SO_VIDEOSHOW_CLIPMODE:ANYCHAT_VIDEOCLIPMODE_AUTO];
        self.theUIImageView.contentMode = UIViewContentModeScaleAspectFit;
    }
    if (flagTimes == 3)
    {
//        [AnyChatPlatform SetSDKOptionInt:BRAC_SO_VIDEOSHOW_CLIPMODE:ANYCHAT_VIDEOCLIPMODE_OVERLAP];
        self.theUIImageView.contentMode = UIViewContentModeScaleToFill;
        flagTimes = 0;
    }

    NSLog(@"%d", flagTimes);
    flagTimes++;

}

- (void)remoteTurnVoiceChat//远端将聊天模式切换成了 语音模式
{
    [self changeVoiceChatMode];
}
- (void)remoteVideoPause//远端视频暂停
{
    self.closeCameraHintView.hidden = NO;
}

- (void)remoteVideoContinue//远端视频继续
{
    self.closeCameraHintView.hidden = YES;
}

- (void)remoteChatClose
{
    if (isOnce)
    {
        isOnce = NO;
        NSLog(@"VideoChatVC____________________BACK");
        AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//[震动:当iPhone侧面的震动关闭时则无效]
        [self FinishVideoChat];
    }
}

- (void)viewWillAppearBOOL)animated
{
    [super viewWillAppear:YES];
    [self setUIControls];
    isOnce = YES;

    //目的是为了在切换聊天模式的时候,能够显示本地视频
    //下面的三行代码是为了打开本地视频,执行完之后会触发 - (void) OnLocalVideoInitid)session 函数
    [AnyChatPlatform UserCameraControl:-1 :NO];//关闭本地视频
    [AnyChatPlatform SetVideoPos:-1 :self :0 :0 :0 :0];
    [AnyChatPlatform UserCameraControl:-1 : YES];//打开本地视频

    [AnyChatPlatform UserSpeakControl: -1:YES];//打开本地麦克风
    //设置扬声器模式
    [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:nil];
    //打开麦克风
    [AnyChatPlatform UserSpeakControl: -1:YES];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:NO];//状态栏白字
}

- (void)viewWillDisappearBOOL)animated
{
    [super viewWillDisappear:animated];
    [[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleDefault animated:NO];//状态栏黑字
    isOnce = NO;
    self.fromID = nil;//该行用于区分第三者的请求---与MyMsgViewController中的isThird....函数耦合
    [self removeFromParentViewController];//删除当前控制器
}

- (void)setYuanJiaoUIView *)view withRadiusNSInteger)num
{
    //设置圆角
    view.layer.cornerRadius = num; //本行代码在IOS6中就可以给label设置圆角,但是在IOS7中不行,还需要再加上下面一行代码
    view.layer.masksToBounds = YES;//默认是NO,超出主层边界的内容统统剪掉
}
#pragma mark - UI

- (void)setUIControls
{

    [[UIApplication sharedApplication] setIdleTimerDisabled:YES];//让屏幕保持被唤醒

    CGFloat marginTopRight = 5;
    CGFloat widthLocalVideo = 100;
    CGFloat heightLocalVideo = 130;

    //本地视频
    self.theLocalView = [[UIView alloc] initWithFrame:CGRectMake(screenWidth - (widthLocalVideo + marginTopRight), marginTopRight + 20, widthLocalVideo, heightLocalVideo)];

    [self.switchCameraBtn setBackgroundImage:[UIImage imageNamed"Icon_camera_w_b"] forState:UIControlStateSelected];

    //Local View line
    self.theLocalView.layer.borderColor = [[UIColor whiteColor] CGColor];
    self.theLocalView.layer.borderWidth = 1.0f;
    //Rounded corners
    self.theLocalView.layer.cornerRadius = 4;
    self.theLocalView.layer.masksToBounds = YES;

    //顶部两个控件的容器
    CGFloat margin = 10;
    CGFloat heightTopContain = 44 + margin * 2;
    UIView *topContainView = [[UIView alloc] initWithFrame:CGRectMake(0, 20, screenWidth, 44 + margin)];

    //切换聊天模式
    CGFloat widthTurn = 90;
    CGFloat heightTurn = 40;

    turnModelCtrl = [[UIControl alloc] initWithFrame:CGRectMake(margin, margin, widthTurn, heightTurn)];
    [self setYuanJiao:turnModelCtrl withRadius:4];
    turnModelCtrl.backgroundColor = [UIColor darkGrayColor];
    [turnModelCtrl addTarget:self actionselector(turnVoiceVC) forControlEvents:UIControlEventTouchUpInside];

    changeChatModeView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 12.75, 18)];//17:24
    changeChatModeView.center = CGPointMake(25/2, heightTurn/2);
    changeChatModeView.image = [UIImage imageNamed"voip_switch_mode_audio_icon"];
    [turnModelCtrl addSubview:changeChatModeView];

    UILabel *turnVideo = [[UILabel alloc] initWithFrame:CGRectMake(23, 0, 65, heightTurn)];
    turnVideo.text = @"切换语音";
    turnVideo.textColor = [UIColor whiteColor];
    turnVideo.font = [UIFont systemFontOfSize:14];
    turnVideo.textAlignment = NSTextAlignmentCenter;
     [turnModelCtrl addSubview:turnVideo];

    //通话时间
    timeLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, heightTopContain)];
    timeLab.center = CGPointMake(screenWidth/2, heightTopContain/2);
    timeLab.textAlignment = NSTextAlignmentCenter;
    timeLab.textColor = [UIColor whiteColor];
    MZTimerLabel *labTime = [[VoiceChatVC labTimeSingleObj] initWithLabel:timeLab];
    [labTime start];

    [topContainView addSubview:turnModelCtrl];
    [topContainView addSubview:timeLab];


    //底部的四个按钮[120*80]3:2
    CGFloat widthBottom  = screenWidth/4;
    CGFloat heightBotton = 49;
    CGFloat imgW = widthBottom;
    CGFloat imgH = 49;//widthBottom*2.0/3;

    containBottomCtrls = [[UIView alloc] initWithFrame:CGRectMake(0, screenHeight - heightBotton, screenWidth, heightBotton)];
    containBottomCtrls.backgroundColor = [UIColor yellowColor];
    containBottomCtrls.alpha = 0.4;
    ctrlTurnLocalVideo = [[UIControl alloc] initWithFrame:CGRectMake(0, 0, widthBottom, heightBotton)];
    ctrlSwitchVideo    = [[UIControl alloc] initWithFrame:CGRectMake(widthBottom, 0, widthBottom, heightBotton)];
    ctrlSwitchVoice    = [[UIControl alloc] initWithFrame:CGRectMake(widthBottom * 2, 0, widthBottom, heightBotton)];
    ctrlHangUp         = [[UIControl alloc] initWithFrame:CGRectMake(widthBottom * 3, 0, widthBottom, heightBotton)];

    [ctrlTurnLocalVideo addTarget:self actionselector(turnLocalVideo) forControlEvents:UIControlEventTouchUpInside];
    [ctrlSwitchVideo    addTarget:self actionselector(switchVideo) forControlEvents:UIControlEventTouchUpInside];
    [ctrlSwitchVoice    addTarget:self actionselector(switchVoice) forControlEvents:UIControlEventTouchUpInside];
    [ctrlHangUp         addTarget:self actionselector(hangUp) forControlEvents:UIControlEventTouchUpInside];


    //切换摄像头、视频开关、麦克风开关、挂断[图片尺寸 120*80 3比2]
    imgV1 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imgW, imgH)];
    imgV2 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imgW, imgH)];
    imgV3 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imgW, imgH)];
    imgV4 = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, imgW, imgH)];

    imgV1.image = [UIImage imageNamed"voip_switch_camera_normal"];
    imgV2.image = [UIImage imageNamed"voip_close_camera_normal"];
    imgV3.image = [UIImage imageNamed:@"voip_mute_normal"];
    imgV4.image = [UIImage imageNamed:@"voip_bottom_logout_normal"];

    [ctrlTurnLocalVideo addSubview:imgV1];
    [ctrlSwitchVideo addSubview:imgV2];
    [ctrlSwitchVoice addSubview:imgV3];
    [ctrlHangUp addSubview:imgV4];

    [containBottomCtrls addSubview:ctrlTurnLocalVideo];
    [containBottomCtrls addSubview:ctrlSwitchVideo];
    [containBottomCtrls addSubview:ctrlSwitchVoice];
    [containBottomCtrls addSubview:ctrlHangUp];

    [self.view addSubview:self.theLocalView];
    [self.view addSubview:topContainView];
    [self.view addSubview:containBottomCtrls];
}

- (void)turnVoiceVC
{
    UIAlertController *alertController = [UIAlertController alertControllerWithTitle:@"提示" message:@"确定要切换语音通话模式?" preferredStyle:UIAlertControllerStyleAlert];
    if (alertController != nil)
    {
        UIAlertAction *cancelAction = [UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:^(UIAlertAction *action)
                                       {

                                       }];

        UIAlertAction *otherAction = [UIAlertAction actionWithTitle:@"确定" style:UIAlertActionStyleDefault handler:^(UIAlertAction *action)
                                      {

                                          [self requestVoiceChat];
                                          [self changeVoiceChatMode];//切换到音频聊天界面

                                      }];

        [alertController addAction:cancelAction];
        [alertController addActiontherAction];

        [self presentViewController:alertController animated:YES completion:nil];
    }
    else
    {
        UIAlertView*alert = [[UIAlertView alloc]initWithTitle:@"提示"
                                                      message:@"确定要切换到语音通话模式?"
                                                     delegate:self
                                            cancelButtonTitle:@"否"
                                            otherButtonTitles:@"是",
                             nil];
        [alert show];

    }

}

- (void)alertViewUIAlertView *)alertView clickedButtonAtIndexNSInteger)buttonIndex
{
    if (buttonIndex == 1)//确定
    {
        [self changeVoiceChatMode];//切换到音频聊天界面
        [self requestVoiceChat];
    }
}

- (void)requestVoiceChat
{
    //告诉远端进行音频聊天
    NSString *jsonStr = [NSString stringWithFormat:@"[\"audio_chat\",\"%@\",\"%@\",\"[%@]\",\"%@\"]\r\n", _userID, _scode, _fromID, @"video_reject"];
    NSThread *downThread = [[NSThread alloc] initWithTarget:self selector:@selector(pushToRemoteChangeChatMode object:jsonStr];
    [downThread start];
    jsonStr = nil;
}

- (void)changeVoiceChatMode
{
    NSMutableDictionary *chatDic = [NSMutableDictionary new];
    [chatDic setObject:self.userID forKey:@"userID"];
    [chatDic setObject:self.fromID forKey:@"fromId"];
    [chatDic setObject:self.scode forKey:@"scode"];
    [chatDic setObject:[NSString stringWithFormat:@"%d", remoteUserid] forKey:@"remoteUserid"];
    [chatDic setObject:@"Voice" forKey:@"chatType"];

    //发送通知到 MainVC
    NSNotification *notification = [NSNotification notificationWithName:@"turnedChatVC" object:nil userInfo:chatDic];
    [[NSNotificationCenter defaultCenter] postNotification:notification];
}

- (void)turnLocalVideo//切换本地前后摄像头
{
    if (!flag1)
    {
        imgV1.image = [UIImage imageNamed:@"voip_switch_camera_pressed"];
        flag1 = YES;
    }
    else
    {
        imgV1.image = [UIImage imageNamed:@"voip_switch_camera_normal"];
        flag1 = NO;
    }
    static int CurrentCameraDevice = 1;
    NSMutableArray* cameraDeviceArray = [AnyChatPlatform EnumVideoCapture];
    if(cameraDeviceArray.count == 2)
    {
        CurrentCameraDevice = (CurrentCameraDevice+1) % 2;
        [AnyChatPlatform SelectVideoCapture:[cameraDeviceArray objectAtIndex:CurrentCameraDevice]];
    }

    [self btnSelectedOnClicked:ctrlTurnLocalVideo];
}

- (void)switchVideo//本地视频开关[打开、关闭]
{
    if (!flag2)
    {
        imgV2.image = [UIImage imageNamed:@"voip_close_camera_pressed"];
        flag2 = YES;
    }
    else
    {
        imgV2.image = [UIImage imageNamed:@"voip_close_camera_normal"];
        flag2 = NO;
    }
    NSString *localCameraState = nil;
    if ([AnyChatPlatform GetCameraState:-1] == 1)
    {   //open local Camera
        [AnyChatPlatform SetVideoPos:-1 :self :0 :0 :0 :0];
        [AnyChatPlatform UserCameraControl:-1 : YES];
        self.theLocalView.hidden = NO;
        ctrlSwitchVideo.selected = NO;
        localCameraState = @"video_continue";
        NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~%@", localCameraState);
    }

    if ([AnyChatPlatform GetCameraState:-1] == 2)
    {   //close local Camera
        [AnyChatPlatform UserCameraControl:-1 :NO];
        self.theLocalView.hidden = YES;
        ctrlSwitchVideo.selected = YES;
        localCameraState = @"video_pause";
        NSLog(@"~~~~~~~~~~~~~~~~~~~~~~~~~~~%@", localCameraState);
    }

    if (localCameraState != nil)//告诉远端,我对本地摄像机的打开 或 关闭状态
    {
        NSString *jsonStr = [NSString stringWithFormat:@"[\"audio_chat\",\"%@\",\"%@\",\"[%@]\",\"%@\"]\r\n", _userID, _scode, _fromID, localCameraState];
        NSThread *downThread = [[NSThread alloc] initWithTarget:self selector:@selector(pushToRemoteSwitchLocalCamera object:jsonStr];
        [downThread start];
        jsonStr = nil;
    }
}

#pragma mark 麦克风开关
- (void)switchVoice
{
    if (!flag3)
    {
        imgV3.image = [UIImage imageNamed:@"voip_mute_pressed"];
        flag3 = YES;
    }
    else
    {
        imgV3.image = [UIImage imageNamed:@"voip_mute_normal"];
        flag3 = NO;
    }
    if (ctrlSwitchVoice.selected == NO)
    {
        [AnyChatPlatform UserSpeakControl:-1 :NO];
        ctrlSwitchVoice.selected = YES;
    }
    else
    {
        [AnyChatPlatform UserSpeakControl: -1:YES];
        ctrlSwitchVoice.selected = NO;
    }

}

#pragma mark 挂断
- (void)hangUp
{
    if (!flag4)
    {
        imgV4.image = [UIImage imageNamed:@"voip_bottom_logout_pressed"];
        flag4 = YES;
    }
    else
    {
        imgV4.image = [UIImage imageNamed:@"voip_bottom_logout_normal"];
        flag4 = NO;
    }
    //关闭摄像头
    NSString *jsonStr = [NSString stringWithFormat:@"[\"audio_chat\",\"%@\",\"%@\",\"[%@]\",\"%@\"]\r\n", _userID, _scode, _fromID, @"video_close"];
    NSThread *downThread = [[NSThread alloc] initWithTarget:self selector:@selector(pushToRemoteCloseVideo object:jsonStr];
    [downThread start];
    jsonStr = nil;

    [ToastView showWithText:@"通话已结束" bottomOffset:110 duration:3];
    AudioServicesPlaySystemSound(kSystemSoundID_Vibrate);//[震动:当iPhone侧面的震动关闭时则无效]
    [self FinishVideoChat];
    [AnyChatPlatform VideoCallControl:BRAC_VIDEOCALL_EVENT_FINISH :self.iRemoteUserId :0 :0 :0 :nil];
}

-(void)pushToRemoteCloseVideoNSString*)sendString
{
    SendStream *stream = [[SendStream alloc] init];

    stream.Flag = @"110";
    [stream initNetworkCommunication];
    [stream writeString:sendString];
    stream = nil;
}

-(void)pushToRemoteSwitchLocalCameraNSString*)sendString
{
    SendStream *stream = [[SendStream alloc] init];

    stream.Flag = @"110";
    [stream initNetworkCommunication];
    [stream writeString:sendString];
    stream = nil;
}

-(void)pushToRemoteChangeChatModeNSString*)sendString
{
    SendStream *stream = [[SendStream alloc] init];

    stream.Flag = @"110";
    [stream initNetworkCommunication];
    [stream writeString:sendString];
    stream = nil;
}

- (void)changeFullScreen
{
    if (!isFullScreen)
    {
        isFullScreen = YES;
    }
    else
    {
        isFullScreen = NO;
    }

    turnModelCtrl.hidden = isFullScreen;
    timeLab.hidden = isFullScreen;
    containBottomCtrls.hidden = isFullScreen;
}

- (void) btnSelectedOnClickedUIControl *)ctrl
{
    if (ctrl.selected)
    {
        ctrl.selected = NO;
    }
    else
    {
        ctrl.selected = YES;
    }
}

#pragma mark - Action Method

- (void) StartVideoChatint) userid//这个userid是对方的userid
{
    remoteUserid = userid;
    //Get a camera, Must be in the real machine.
    NSMutableArray* cameraDeviceArray = [AnyChatPlatform EnumVideoCapture];
    if (cameraDeviceArray.count > 0)
    {
        [AnyChatPlatform SelectVideoCapture:[cameraDeviceArray objectAtIndex:1]];
    }

    //显示远端视频
    self.theUIImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 20, screenWidth, screenHeight - 20)];
    self.theUIImageView.backgroundColor = [UIColor grayColor];
    self.theUIImageView.contentMode = UIViewContentModeScaleAspectFill;//设置本地视频的显模式 避免视频图像挤压

    //空白处设置透明UI 用于切换全屏
    ctrlSwitchFullScreen = [[UIControl alloc] initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
    [ctrlSwitchFullScreen addTarget:self action:@selector(changeFullScreen) forControlEvents:UIControlEventTouchUpInside];

    // open local video[执行这段代码之后 会调用 OnLocalVideoInit[进行摄像头的初始化]]
    [AnyChatPlatform SetSDKOptionInt:BRAC_SO_LOCALVIDEO_OVERLAY :1];
    [AnyChatPlatform UserSpeakControl: -1:YES];//打开本地麦克风
    [AnyChatPlatform SetVideoPos:-1 :self :0 :0 :0 :0];
    [AnyChatPlatform UserCameraControl:-1 : YES];

    // request other user video
    [AnyChatPlatform UserSpeakControl: userid:YES];
    [AnyChatPlatform SetVideoPos:userid: self.theUIImageView:0:0:0:0];
    [AnyChatPlatform UserCameraControl:userid : YES];

    self.iRemoteUserId = userid;

    [AnyChatPlatform SetSDKOptionInt:BRAC_SO_LOCALVIDEO_ORIENTATION : self.interfaceOrientation];
    [self.view addSubview:self.theUIImageView];
    [self.view addSubview:self.closeCameraHintView];
    [self.view addSubview:ctrlSwitchFullScreen];

    self.closeCameraHintView.hidden = YES;
}

- (void)viewDidAppearBOOL)animated
{
    [super viewDidAppear:animated];
}

- (void) FinishVideoChat
{
    [self recodeChatedTimes];
    //释放本地摄像头和音频采集设备[执行此操作之后,AnyChat SDK自动调用“摄像头硬件资源释放”方法On LocalVideoRelease]
    [AnyChatPlatform UserSpeakControl: -1 : NO];
    [AnyChatPlatform UserCameraControl: -1 : NO];

    [AnyChatPlatform UserSpeakControl: self.iRemoteUserId : NO];
    [AnyChatPlatform UserCameraControl: self.iRemoteUserId : NO];

    self.iRemoteUserId = -1;
    [AnyChatPlatform LeaveRoom:-1];
    [self.navigationController popViewControllerAnimated:YES];
    [VoiceChatVC clearTime];
}

#pragma mark 记录聊天时间
- (void)recodeChatedTimes
{
    //将通话时间显示到聊天记录中
    NSString *chatedTimes = timeLab.text;
    NSLog(@"聊天时间为:%@", chatedTimes);
    NSMutableDictionary *dic = [NSMutableDictionary new];
    [dic setObject:chatedTimes forKey:@"chatedTimes"];
    [dic setObject:@"videoChat" forKey:@"chatType"];
    //发送到 SendMsgViewController
    NSNotification *notification = [NSNotification notificationWithName:@"chatedTimes" object:nil userInfo:dic];
    [[NSNotificationCenter defaultCenter] postNotification:notification];
}

- (void) OnLocalVideoReleaseid)sender
{
    if(self.localVideoSurface)
    {
        self.localVideoSurface = nil;
    }
}

//该函数是传输视频的核心
- (void) OnLocalVideoInitid)session
{
    self.localVideoSurface = [AVCaptureVideoPreviewLayer layerWithSession: (AVCaptureSession*)session];
    self.localVideoSurface.frame = CGRectMake(0, 0, 100.0, 130.0);
    self.localVideoSurface.videoGravity = AVLayerVideoGravityResizeAspectFill;

    [self.theLocalView.layer addSublayer:self.localVideoSurface];
}

- (BOOL)prefersStatusBarHidden
{
    return YES;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}

-(void)dealloc
{
    theAnyChat = nil;
    self.localVideoSurface = nil;
    self.theUIImageView = nil;
    self.theLocalView = nil;
    self.switchCameraBtn = nil;
//    self.endCallBtn = nil;
//    self.voiceBtn = nil;
//    self.cameraBtn = nil;

    ctrlSwitchFullScreen = nil;
    //顶部
    timeLab = nil;
    turnModelCtrl = nil;
    //底部
    containBottomCtrls = nil;
    ctrlTurnLocalVideo = nil;
    ctrlSwitchVideo = nil;
    ctrlSwitchVoice = nil;
    ctrlHangUp = nil;

    //底部按钮的图片
    imgV1 = nil;
    imgV2 = nil;
    imgV3 = nil;
    imgV4 = nil;

    //删除通知
    [[NSNotificationCenter  defaultCenter] removeObserver:self  name:@"voice_close"     object:nil];
    [[NSNotificationCenter  defaultCenter] removeObserver:self  name:@"video_pause"     object:nil];
    [[NSNotificationCenter  defaultCenter] removeObserver:self  name:@"video_continue"  object:nil];
    [[NSNotificationCenter  defaultCenter] removeObserver:self  name:@"voice_reject"    object:nil];
    [[NSNotificationCenter  defaultCenter] removeObserver:self  name:@"video_reject"    object:nil];


}


@end
回复 支持 反对

使用道具 举报

14

主题

87

帖子

258

积分

中级会员

Rank: 3Rank: 3

积分
258
30#
 楼主| 发表于 2016-2-2 16:58:41 | 只看该作者

无效无效无效无效

本帖最后由 kenshin 于 2016-2-2 16:59 编辑

无效无效无效无效无效
回复 支持 反对

使用道具 举报

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

本版积分规则

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

GMT+8, 2024-5-3 21:56 , Processed in 0.199196 second(s), 20 queries .

Powered by Discuz! X3

© 2001-2013 Comsenz Inc.

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