android视频通话
1. Android开发视频通话怎么实现
/**
* Android视频聊天
* 1、初始化SDK 2、连接服务器、 3、用户登录;4、进入房间;5、打开本地视频;6、请求对方视频
*/
public class VideoChatActivity extends Activity implements AnyChatBaseEvent
{
private AnyChatCoreSDK anychat; // 核心SDK
private SurfaceView remoteSurfaceView; // 对方视频
private SurfaceView localSurfaceView; // 本地视频
private ConfigEntity configEntity;
private boolean bSelfVideoOpened = false; // 本地视频是否已打开
private boolean bOtherVideoOpened = false; // 对方视频是否已打开
private TimerTask mTimerTask; // 定时器
private Timer mTimer = new Timer(true);
private Handler handler; // 用Handler来不间断刷新即时视频
private List<String> userlist = new ArrayList<String>();//保存在线用户列表
private int userid; // 用户ID
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_chat);
remoteSurfaceView = (SurfaceView) findViewById(R.id.surface_remote);
localSurfaceView = (SurfaceView) findViewById(R.id.surface_local);
configEntity = ConfigService.LoadConfig(this);//加载视频通话设置
loginSystem();// 初始化SDK 连接服务器
mTimerTask = new TimerTask(){
public void run(){
Message mesasge = new Message();
handler.sendMessage(mesasge);
}
};
mTimer.schele(mTimerTask, 1000, 100);
handler = new Handler(){
@Override
public void handleMessage(Message msg){
VideoChat();// 不间断显示即时视频通话画面
super.handleMessage(msg);
}
};
}
// 初始化SDK 连接服务器
private void loginSystem(){
if (anychat == null){
anychat = new AnyChatCoreSDK();
anychat.SetBaseEvent(this); // 设置基本事件回调函数
if (configEntity.useARMv6Lib != 0) // 使用ARMv6指令集
anychat.SetSDKOptionInt(AnyChatDefine.
BRAC_SO_CORESDK_USEARMV6LIB, 1);
anychat.InitSDK(android.os.Build.VERSION.SDK_INT, 0); // 初始化SDK
}
anychat.Connect("demo.anychat.cn", 8906);// 连接服务器
}
// 显示即时视频通话画面
public void VideoChat(){
if (!bOtherVideoOpened){
if (anychat.GetCameraState(userid) == 2
&& anychat.GetUserVideoWidth(userid) != 0){
SurfaceHolder holder = remoteSurfaceView.getHolder();
holder.setFormat(PixelFormat.RGB_565);
holder.setFixedSize(anychat.GetUserVideoWidth(userid),
anychat.GetUserVideoHeight(userid));
Surface s = holder.getSurface(); // 获得视频画面
anychat.SetVideoPos(userid, s, 0, 0, 0, 0); // 调用API显示视频画面
bOtherVideoOpened = true;
}
if (!bSelfVideoOpened){
if (anychat.GetCameraState(-1) == 2
&& anychat.GetUserVideoWidth(-1) != 0){
SurfaceHolder holder = localSurfaceView.getHolder();
holder.setFormat(PixelFormat.RGB_565);
holder.setFixedSize(anychat.GetUserVideoWidth(-1),
anychat.GetUserVideoHeight(-1));
Surface s = holder.getSurface();
anychat.SetVideoPos(-1, s, 0, 0, 0, 0);
bSelfVideoOpened = true;
}
}
}
public void OnAnyChatConnectMessage(boolean bSuccess){
if (!bSuccess){
Toast.makeText(VideoChatActivity.this, "连接服务器失败,自动重连,请稍后...", Toast.LENGTH_SHORT).show();
}
anychat.Login("android", ""); // 服务器连接成功 用户登录
}
public void OnAnyChatLoginMessage(int dwUserId, int dwErrorCode){
if (dwErrorCode == 0) {
Toast.makeText(this, "登录成功!", Toast.LENGTH_SHORT).show();
anychat.EnterRoom(1, ""); // 用户登录成功 进入房间
ApplyVideoConfig();
} else {
Toast.makeText(this, "登录失败,错误代码:" + dwErrorCode, Toast.LENGTH_SHORT).show();
}
}
public void OnAnyChatEnterRoomMessage(int dwRoomId, int dwErrorCode){
if (dwErrorCode == 0) { // 进入房间成功 打开本地音视频
Toast.makeText(this, "进入房间成功", Toast.LENGTH_SHORT).show();
anychat.UserCameraControl(-1, 1); // 打开本地视频
anychat.UserSpeakControl(-1, 1); // 打开本地音频
} else {
Toast.makeText(this, "进入房间失败,错误代码:" + dwErrorCode, Toast.LENGTH_SHORT).show();
}
}
public void OnAnyChatOnlineUserMessage(int dwUserNum, int dwRoomId){
if (dwRoomId == 1){
int user[] = anychat.GetOnlineUser();
if (user.length != 0){
for (int i = 0; i < user.length; i++){
userlist.add(user[i]+"");
. }
String temp =userlist.get(0);
userid = Integer.parseInt(temp);
anychat.UserCameraControl(userid, 1);// 请求用户视频
anychat.UserSpeakControl(userid, 1); // 请求用户音频
}
else {
Toast.makeText(VideoChatActivity.this, "当前没有在线用户", Toast.LENGTH_SHORT).show();
}
}
}
public void OnAnyChatUserAtRoomMessage(int dwUserId, boolean bEnter){
if (bEnter) {//新用户进入房间
userlist.add(dwUserId+"");
}
else { //用户离开房间
if (dwUserId == userid)
{
Toast.makeText(VideoChatActivity.this, "视频用户已下线", Toast.LENGTH_SHORT).show();
anychat.UserCameraControl(userid, 0);// 关闭用户视频
anychat.UserSpeakControl(userid, 0); // 关闭用户音频
userlist.remove(userid+""); //移除该用户
if (userlist.size() != 0)
{
String temp =userlist.get(0);
userid = Integer.parseInt(temp);
anychat.UserCameraControl(userid, 1);// 请求其他用户视频
anychat.UserSpeakControl(userid, 1); // 请求其他用户音频
}
}
141. else {
userlist.remove(dwUserId+""); //移除该用户
}
}
}
public void OnAnyChatLinkCloseMessage(int dwErrorCode){
Toast.makeText(VideoChatActivity.this, "连接关闭,error:" + dwErrorCode, Toast.LENGTH_SHORT).show();
}
@Override
protected void onDestroy(){ //程序退出
anychat.LeaveRoom(-1); //离开房间
anychat.Logout(); //注销登录
anychat.Release(); //释放资源
mTimer.cancel();
super.onDestroy();
}
// 根据配置文件配置视频参数
private void ApplyVideoConfig(){
if (configEntity.configMode == 1) // 自定义视频参数配置
{
// 设置本地视频编码的码率(如果码率为0,则表示使用质量优先模式)
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_BITRATECTRL,configEntity.videoBitrate);
if (configEntity.videoBitrate == 0)
{
// 设置本地视频编码的质量
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_QUALITYCTRL,configEntity.videoQuality);
}
// 设置本地视频编码的帧率
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_FPSCTRL,configEntity.videoFps);
// 设置本地视频编码的关键帧间隔
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_GOPCTRL,configEntity.videoFps * 4);
// 设置本地视频采集分辨率
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_WIDTHCTRL,configEntity.resolution_width);
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_HEIGHTCTRL,configEntity.resolution_height);
// 设置视频编码预设参数(值越大,编码质量越高,占用CPU资源也会越高)
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_PRESETCTRL,configEntity.videoPreset);
}
// 让视频参数生效
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_APPLYPARAM,configEntity.configMode);
// P2P设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_NETWORK_P2PPOLITIC,configEntity.enableP2P);
// 本地视频Overlay模式设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_OVERLAY,configEntity.videoOverlay);
// 回音消除设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_AUDIO_ECHOCTRL,configEntity.enableAEC);
// 平台硬件编码设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_CORESDK_USEHWCODEC,configEntity.useHWCodec);
// 视频旋转模式设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_ROTATECTRL,configEntity.videorotatemode);
// 视频平滑播放模式设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_STREAM_SMOOTHPLAYMODE,configEntity.smoothPlayMode);
// 视频采集驱动设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_CAPDRIVER,configEntity.videoCapDriver);
// 本地视频采集偏色修正设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_FIXCOLORDEVIA,configEntity.fixcolordeviation);
// 视频显示驱动设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_VIDEOSHOW_DRIVERCTRL,configEntity.videoShowDriver);
}
}
2. android 开发中如何实现视频通话功能 !求大神指点!功能实现的思路,及用到的知识点!!感激不尽!!
/**
* Android视频聊天
* 1、初始化SDK 2、连接服务器、 3、用户登录;4、进入房间;5、打开本地视频;6、请求对方视频
*/
public class VideoChatActivity extends Activity implements AnyChatBaseEvent
{
private AnyChatCoreSDK anychat; // 核心SDK
private SurfaceView remoteSurfaceView; // 对方视频
private SurfaceView localSurfaceView; // 本地视频
private ConfigEntity configEntity;
private boolean bSelfVideoOpened = false; // 本地视频是否已打开
private boolean bOtherVideoOpened = false; // 对方视频是否已打开
private TimerTask mTimerTask; // 定时器
private Timer mTimer = new Timer(true);
private Handler handler; // 用Handler来不间断刷新即时视频
private List<String> userlist = new ArrayList<String>();//保存在线用户列表
private int userid; // 用户ID
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_chat);
remoteSurfaceView = (SurfaceView) findViewById(R.id.surface_remote);
localSurfaceView = (SurfaceView) findViewById(R.id.surface_local);
configEntity = ConfigService.LoadConfig(this);//加载视频通话设置
loginSystem();// 初始化SDK 连接服务器
mTimerTask = new TimerTask(){
public void run(){
Message mesasge = new Message();
handler.sendMessage(mesasge);
}
};
mTimer.schele(mTimerTask, 1000, 100);
handler = new Handler(){
@Override
public void handleMessage(Message msg){
VideoChat();// 不间断显示即时视频通话画面
super.handleMessage(msg);
}
};
}
// 初始化SDK 连接服务器
private void loginSystem(){
if (anychat == null){
anychat = new AnyChatCoreSDK();
anychat.SetBaseEvent(this); // 设置基本事件回调函数
if (configEntity.useARMv6Lib != 0) // 使用ARMv6指令集
anychat.SetSDKOptionInt(AnyChatDefine.
BRAC_SO_CORESDK_USEARMV6LIB, 1);
anychat.InitSDK(android.os.Build.VERSION.SDK_INT, 0); // 初始化SDK
}
anychat.Connect("demo.anychat.cn", 8906);// 连接服务器
}
// 显示即时视频通话画面
public void VideoChat(){
if (!bOtherVideoOpened){
if (anychat.GetCameraState(userid) == 2
&& anychat.GetUserVideoWidth(userid) != 0){
SurfaceHolder holder = remoteSurfaceView.getHolder();
holder.setFormat(PixelFormat.RGB_565);
holder.setFixedSize(anychat.GetUserVideoWidth(userid),
anychat.GetUserVideoHeight(userid));
Surface s = holder.getSurface(); // 获得视频画面
anychat.SetVideoPos(userid, s, 0, 0, 0, 0); // 调用API显示视频画面
bOtherVideoOpened = true;
}
if (!bSelfVideoOpened){
if (anychat.GetCameraState(-1) == 2
&& anychat.GetUserVideoWidth(-1) != 0){
SurfaceHolder holder = localSurfaceView.getHolder();
holder.setFormat(PixelFormat.RGB_565);
holder.setFixedSize(anychat.GetUserVideoWidth(-1),
anychat.GetUserVideoHeight(-1));
Surface s = holder.getSurface();
anychat.SetVideoPos(-1, s, 0, 0, 0, 0);
bSelfVideoOpened = true;
}
}
}
public void OnAnyChatConnectMessage(boolean bSuccess){
if (!bSuccess){
Toast.makeText(VideoChatActivity.this, "连接服务器失败,自动重连,请稍后...", Toast.LENGTH_SHORT).show();
}
anychat.Login("android", ""); // 服务器连接成功 用户登录
}
public void OnAnyChatLoginMessage(int dwUserId, int dwErrorCode){
if (dwErrorCode == 0) {
Toast.makeText(this, "登录成功!", Toast.LENGTH_SHORT).show();
anychat.EnterRoom(1, ""); // 用户登录成功 进入房间
ApplyVideoConfig();
} else {
Toast.makeText(this, "登录失败,错误代码:" + dwErrorCode, Toast.LENGTH_SHORT).show();
}
}
public void OnAnyChatEnterRoomMessage(int dwRoomId, int dwErrorCode){
if (dwErrorCode == 0) { // 进入房间成功 打开本地音视频
Toast.makeText(this, "进入房间成功", Toast.LENGTH_SHORT).show();
anychat.UserCameraControl(-1, 1); // 打开本地视频
anychat.UserSpeakControl(-1, 1); // 打开本地音频
} else {
Toast.makeText(this, "进入房间失败,错误代码:" + dwErrorCode, Toast.LENGTH_SHORT).show();
}
}
public void OnAnyChatOnlineUserMessage(int dwUserNum, int dwRoomId){
if (dwRoomId == 1){
int user[] = anychat.GetOnlineUser();
if (user.length != 0){
for (int i = 0; i < user.length; i++){
userlist.add(user[i]+"");
. }
String temp =userlist.get(0);
userid = Integer.parseInt(temp);
anychat.UserCameraControl(userid, 1);// 请求用户视频
anychat.UserSpeakControl(userid, 1); // 请求用户音频
}
else {
Toast.makeText(VideoChatActivity.this, "当前没有在线用户", Toast.LENGTH_SHORT).show();
}
}
}
public void OnAnyChatUserAtRoomMessage(int dwUserId, boolean bEnter){
if (bEnter) {//新用户进入房间
userlist.add(dwUserId+"");
}
else { //用户离开房间
if (dwUserId == userid)
{
Toast.makeText(VideoChatActivity.this, "视频用户已下线", Toast.LENGTH_SHORT).show();
anychat.UserCameraControl(userid, 0);// 关闭用户视频
anychat.UserSpeakControl(userid, 0); // 关闭用户音频
userlist.remove(userid+""); //移除该用户
if (userlist.size() != 0)
{
String temp =userlist.get(0);
userid = Integer.parseInt(temp);
anychat.UserCameraControl(userid, 1);// 请求其他用户视频
anychat.UserSpeakControl(userid, 1); // 请求其他用户音频
}
}
141. else {
userlist.remove(dwUserId+""); //移除该用户
}
}
}
public void OnAnyChatLinkCloseMessage(int dwErrorCode){
Toast.makeText(VideoChatActivity.this, "连接关闭,error:" + dwErrorCode, Toast.LENGTH_SHORT).show();
}
@Override
protected void onDestroy(){ //程序退出
anychat.LeaveRoom(-1); //离开房间
anychat.Logout(); //注销登录
anychat.Release(); //释放资源
mTimer.cancel();
super.onDestroy();
}
// 根据配置文件配置视频参数
private void ApplyVideoConfig(){
if (configEntity.configMode == 1) // 自定义视频参数配置
{
// 设置本地视频编码的码率(如果码率为0,则表示使用质量优先模式)
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_BITRATECTRL,configEntity.videoBitrate);
if (configEntity.videoBitrate == 0)
{
// 设置本地视频编码的质量
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_QUALITYCTRL,configEntity.videoQuality);
}
// 设置本地视频编码的帧率
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_FPSCTRL,configEntity.videoFps);
// 设置本地视频编码的关键帧间隔
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_GOPCTRL,configEntity.videoFps * 4);
// 设置本地视频采集分辨率
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_WIDTHCTRL,configEntity.resolution_width);
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_HEIGHTCTRL,configEntity.resolution_height);
// 设置视频编码预设参数(值越大,编码质量越高,占用CPU资源也会越高)
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_PRESETCTRL,configEntity.videoPreset);
}
// 让视频参数生效
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_APPLYPARAM,configEntity.configMode);
// P2P设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_NETWORK_P2PPOLITIC,configEntity.enableP2P);
// 本地视频Overlay模式设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_OVERLAY,configEntity.videoOverlay);
// 回音消除设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_AUDIO_ECHOCTRL,configEntity.enableAEC);
// 平台硬件编码设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_CORESDK_USEHWCODEC,configEntity.useHWCodec);
// 视频旋转模式设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_ROTATECTRL,configEntity.videorotatemode);
// 视频平滑播放模式设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_STREAM_SMOOTHPLAYMODE,configEntity.smoothPlayMode);
// 视频采集驱动设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_CAPDRIVER,configEntity.videoCapDriver);
// 本地视频采集偏色修正设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_LOCALVIDEO_FIXCOLORDEVIA,configEntity.fixcolordeviation);
// 视频显示驱动设置
anychat.SetSDKOptionInt(AnyChatDefine.BRAC_SO_VIDEOSHOW_DRIVERCTRL,configEntity.videoShowDriver);
}
}
3. 安卓手机能打视频电话吗
手机使用视频通话需要满足以下条件方可实现:
1.双方手机均需要支持视频通话功能。
2.手机SIM卡需支持3G/4G网络。
3.手机需要在3G或4G网络信号覆盖范围内,且当前正在使用3G/4G网络。
注:
1.目前电信网络不支持视频通话功能;
2.移动4G网络不支持视频通话功能(支持VoLTE的机型除外)。
3.使用手机视频通话功能不需要消耗流量。
4. 手机怎么视频通话
你要先办一个可以视频通话的卡,打电话的时候有个视频选项,并且手机上要带有前置摄像头,和你通话的那个人也要有摄像头。
5. 安卓系统怎么视频通话
拨打可视电话,主叫和被叫双方终端须支持可视电话功能,方法如下:
1.在手机上输入被叫号码后,选择“选项”中的“视频通话”,即可发起可视电话呼叫;
2.也可以通过通讯录选择向某联系人发起可视电话呼叫。
6. Android基于SDK如何简易实现视频一对一通话
即构科技的视频sdk,兼容15000+设备终端,跨平台支持iOS、Android、H5、Windows、macOS等
7. 怎么实现android实时视频通话功能
/**
* Android视频聊天
* 1、初始化SDK 2、连接服务器、 3、用户登录;4、进入房间;5、打开本地视频;6、请求对方视频
*/
public class VideoChatActivity extends Activity implements AnyChatBaseEvent
{
private AnyChatCoreSDK anychat; // 核心SDK
private SurfaceView remoteSurfaceView; // 对方视频
private SurfaceView localSurfaceView; // 本地视频
private ConfigEntity configEntity;
private boolean bSelfVideoOpened = false; // 本地视频是否已打开
private boolean bOtherVideoOpened = false; // 对方视频是否已打开
private TimerTask mTimerTask; // 定时器
private Timer mTimer = new Timer(true);
private Handler handler; // 用Handler来不间断刷新即时视频
private List<String> userlist = new ArrayList<String>();//保存在线用户列表
private int userid; // 用户ID
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video_chat);
remoteSurfaceView = (SurfaceView) findViewById(R.id.surface_remote);
localSurfaceView = (SurfaceView) findViewById(R.id.surface_local);
configEntity = ConfigService.LoadConfig(this);//加载视频通话设置
loginSystem();// 初始化SDK 连接服务器
mTimerTask = new TimerTask(){
public void run(){
Message mesasge = new Message();
handler.sendMessage(mesasge);
}
};
mTimer.schele(mTimerTask, 1000, 100);
handler = new Handler(){
@Override
public void handleMessage(Message msg){
VideoChat();// 不间断显示即时视频通话画面
super.handleMessage(msg);
}
};
}
8. 在android 上实现点对点视频通话难不难
不难,可用找第三方提供对应的音视频SDK,ZEGO即构科技就不错,最近还获得了融资。总之他们的音视频SDK支持在android 上实现点对点视频通话,并且接入简单,API可用灵活调用。
9. 安卓上如何实现多人视频通话该用什么SDK
我认为我可以提供一些参考意见!