点对点视频 如何显示对方的画面 我这个不显示对方
package com.example.zzzim.activity;
import com.easemob.chat.EMCallStateChangeListener;
import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMVideoCallHelper;
import com.easemob.easeui.EaseConstant;
import com.easemob.easeui.ui.EaseBaseActivity;
import com.easemob.exceptions.EMNetworkUnconnectedException;
import com.easemob.exceptions.EMNoActiveCallException;
import com.easemob.exceptions.EMServiceNotReadyException;
import com.example.zzzim.R;
import com.example.zzzim.utils.CameraHelper;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
/**
* 视频通话
*
* @author Lyan 2015年12月3日
*/
public class MyTalkingActivity extends EaseBaseActivity implements OnClickListener {
//视频通话需要的相关资源
private SurfaceView mineSur,otherSur;
private SurfaceHolder mineHolder,otherHolder;
public EMVideoCallHelper callHelper;
private CameraHelper cameraHelper;
// 功能按钮控件
private TextView jie, da, jujie, gua, shipin;
private Context context;
private boolean isInComingCall;//是否是来电话-->false
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.custom_frag);
context = this;
registerReceiver();//注册广播---->用来提示用户 有来电
initTextView();// 初始化接 打 拒接 挂 播视频按键
initSurFaceView();//初始化surfaceView
talkState();//通话状态
// 设置点击事件
jie.setOnClickListener(this);
da.setOnClickListener(this);
jujie.setOnClickListener(this);
gua.setOnClickListener(this);
shipin.setOnClickListener(this);
// Log.i("isInComingCall-->来电!", isInComingCall+"");
Toast.makeText(context, isInComingCall+"" , Toast.LENGTH_SHORT).show();//展示默认值-->false
// 获取callHelper,cameraHelper
callHelper = EMVideoCallHelper.getInstance();
cameraHelper = new CameraHelper(callHelper, mineHolder,context);
// 设置显示对方图像的surfaceview
callHelper.setSurfaceView(otherSur);
mineHolder.addCallback(new LocalCallback());
otherHolder.addCallback(new OppositeCallback());
// cameraHelper.setStartFlag(true);
}
/**
* 本地SurfaceHolder callback
*
*/
class LocalCallback implements SurfaceHolder.Callback {
@Override
public void surfaceCreated(SurfaceHolder holder) {
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
cameraHelper.startCapture();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
}
/**
* 对方SurfaceHolder callback
*/
class OppositeCallback implements SurfaceHolder.Callback {
@Override
public void surfaceCreated(SurfaceHolder holder) {
holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
callHelper.setRenderFlag(true);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
callHelper.onWindowResize(width, height, format);
if (!cameraHelper.isStarted()) {
if (true) {
try {
// 拨打视频通话
EMChatManager.getInstance().makeVideoCall("qwe");
// 通知cameraHelper可以写入数据
cameraHelper.setStartFlag(true);
} catch (EMServiceNotReadyException e) {
Toast.makeText(context, R.string.Is_not_yet_connected_to_the_server , 1).show();
}
}
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
callHelper.setRenderFlag(false);
}
}
/*
* 初始化surfaceView
*/
private void initSurFaceView() {
mineSur = (SurfaceView) findViewById(R.id.sur_yours);
mineSur.setZOrderMediaOverlay(true);
mineSur.setZOrderOnTop(true);
mineHolder = mineSur.getHolder();
otherSur = (SurfaceView) findViewById(R.id.sur_others);
otherHolder = otherSur.getHolder();
}
/*
* 动态注册广播
*/
private void registerReceiver(){
IntentFilter callFilter = new IntentFilter(EMChatManager.getInstance().getIncomingCallBroadcastAction());
context.registerReceiver(new CallReceiver(), callFilter);
}
/*
* 实时通话的广播
*/
private class CallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// 拨打方用户
String from = intent.getStringExtra(EaseConstant.EXTRA_USER_ID);
Toast.makeText(context, "来电人是--->"+from, Toast.LENGTH_SHORT).show();
// 类型
String type = intent.getStringExtra(EaseConstant.EXTRA_CHAT_TYPE);
if("video".equals(type)){ //视频通话
Toast.makeText(context, "来视频了情接听!", Toast.LENGTH_SHORT).show();
}else{ //音频通话
Toast.makeText(context, "来电话了请接听!", Toast.LENGTH_SHORT).show();
}
}
}
/*
* 初始化按键 分别为 接 打 拒接 挂 播视频
*/
private void initTextView() {
jie = (TextView) findViewById(R.id.frag_tv);
da = (TextView) findViewById(R.id.come_call);
jujie = (TextView) findViewById(R.id.bu_jie);
gua = (TextView) findViewById(R.id.gua);
shipin = (TextView) findViewById(R.id.shipin);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.frag_tv://接
try {
EMChatManager.getInstance().answerCall();
Toast.makeText(context, "接", Toast.LENGTH_SHORT).show();
} catch (EMNoActiveCallException e) {
e.printStackTrace();
} catch (EMNetworkUnconnectedException e) {
e.printStackTrace();
}
break;
case R.id.come_call://播打语音
try {
EMChatManager.getInstance().makeVoiceCall("asd");//测试好友
Toast.makeText(context, "播打语音", Toast.LENGTH_SHORT).show();
} catch (EMServiceNotReadyException e) {
e.printStackTrace();
}
break;
case R.id.bu_jie://不接
try {
EMChatManager.getInstance().rejectCall();
Toast.makeText(context, "不接", Toast.LENGTH_SHORT).show();
} catch (EMNoActiveCallException e) {
e.printStackTrace();
}
break;
case R.id.gua://挂
EMChatManager.getInstance().endCall();
Toast.makeText(context, "挂", Toast.LENGTH_SHORT).show();
break;
case R.id.shipin://拨打视频
try {
EMChatManager.getInstance().makeVideoCall("asd");
} catch (EMServiceNotReadyException e) {
e.printStackTrace();
}
break;
}
}
/**
* 设置通话状态监听
* @param listener
*/
private void talkState() {
EMChatManager.getInstance().addVoiceCallStateChangeListener(new EMCallStateChangeListener() {
@Override
public void onCallStateChanged(CallState callState, CallError error) {
switch (callState) {
case CONNECTING: // 正在连接对方
Log.i("talkState", "正在连接对方");
break;
case CONNECTED: // 双方已经建立连接
Log.i("talkState", "双方已经建立连接");
break;
case ACCEPTED: // 电话接通成功
callHelper.setRenderFlag(true);
Log.i("talkState", "电话接通成功");
break;
case DISCONNNECTED: // 电话断了
Log.i("talkState", "电话断了");
break;
default:
break;
}
}
});
}
}
import com.easemob.chat.EMCallStateChangeListener;
import com.easemob.chat.EMChatManager;
import com.easemob.chat.EMVideoCallHelper;
import com.easemob.easeui.EaseConstant;
import com.easemob.easeui.ui.EaseBaseActivity;
import com.easemob.exceptions.EMNetworkUnconnectedException;
import com.easemob.exceptions.EMNoActiveCallException;
import com.easemob.exceptions.EMServiceNotReadyException;
import com.example.zzzim.R;
import com.example.zzzim.utils.CameraHelper;
import android.content.BroadcastReceiver;
import android.content.Context;
import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.util.Log;
import android.view.SurfaceHolder;
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.TextView;
import android.widget.Toast;
/**
* 视频通话
*
* @author Lyan 2015年12月3日
*/
public class MyTalkingActivity extends EaseBaseActivity implements OnClickListener {
//视频通话需要的相关资源
private SurfaceView mineSur,otherSur;
private SurfaceHolder mineHolder,otherHolder;
public EMVideoCallHelper callHelper;
private CameraHelper cameraHelper;
// 功能按钮控件
private TextView jie, da, jujie, gua, shipin;
private Context context;
private boolean isInComingCall;//是否是来电话-->false
@Override
protected void onCreate(Bundle arg0) {
super.onCreate(arg0);
setContentView(R.layout.custom_frag);
context = this;
registerReceiver();//注册广播---->用来提示用户 有来电
initTextView();// 初始化接 打 拒接 挂 播视频按键
initSurFaceView();//初始化surfaceView
talkState();//通话状态
// 设置点击事件
jie.setOnClickListener(this);
da.setOnClickListener(this);
jujie.setOnClickListener(this);
gua.setOnClickListener(this);
shipin.setOnClickListener(this);
// Log.i("isInComingCall-->来电!", isInComingCall+"");
Toast.makeText(context, isInComingCall+"" , Toast.LENGTH_SHORT).show();//展示默认值-->false
// 获取callHelper,cameraHelper
callHelper = EMVideoCallHelper.getInstance();
cameraHelper = new CameraHelper(callHelper, mineHolder,context);
// 设置显示对方图像的surfaceview
callHelper.setSurfaceView(otherSur);
mineHolder.addCallback(new LocalCallback());
otherHolder.addCallback(new OppositeCallback());
// cameraHelper.setStartFlag(true);
}
/**
* 本地SurfaceHolder callback
*
*/
class LocalCallback implements SurfaceHolder.Callback {
@Override
public void surfaceCreated(SurfaceHolder holder) {
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
cameraHelper.startCapture();
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
}
}
/**
* 对方SurfaceHolder callback
*/
class OppositeCallback implements SurfaceHolder.Callback {
@Override
public void surfaceCreated(SurfaceHolder holder) {
holder.setType(SurfaceHolder.SURFACE_TYPE_GPU);
callHelper.setRenderFlag(true);
}
@Override
public void surfaceChanged(SurfaceHolder holder, int format, int width, int height) {
callHelper.onWindowResize(width, height, format);
if (!cameraHelper.isStarted()) {
if (true) {
try {
// 拨打视频通话
EMChatManager.getInstance().makeVideoCall("qwe");
// 通知cameraHelper可以写入数据
cameraHelper.setStartFlag(true);
} catch (EMServiceNotReadyException e) {
Toast.makeText(context, R.string.Is_not_yet_connected_to_the_server , 1).show();
}
}
}
}
@Override
public void surfaceDestroyed(SurfaceHolder holder) {
callHelper.setRenderFlag(false);
}
}
/*
* 初始化surfaceView
*/
private void initSurFaceView() {
mineSur = (SurfaceView) findViewById(R.id.sur_yours);
mineSur.setZOrderMediaOverlay(true);
mineSur.setZOrderOnTop(true);
mineHolder = mineSur.getHolder();
otherSur = (SurfaceView) findViewById(R.id.sur_others);
otherHolder = otherSur.getHolder();
}
/*
* 动态注册广播
*/
private void registerReceiver(){
IntentFilter callFilter = new IntentFilter(EMChatManager.getInstance().getIncomingCallBroadcastAction());
context.registerReceiver(new CallReceiver(), callFilter);
}
/*
* 实时通话的广播
*/
private class CallReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
// 拨打方用户
String from = intent.getStringExtra(EaseConstant.EXTRA_USER_ID);
Toast.makeText(context, "来电人是--->"+from, Toast.LENGTH_SHORT).show();
// 类型
String type = intent.getStringExtra(EaseConstant.EXTRA_CHAT_TYPE);
if("video".equals(type)){ //视频通话
Toast.makeText(context, "来视频了情接听!", Toast.LENGTH_SHORT).show();
}else{ //音频通话
Toast.makeText(context, "来电话了请接听!", Toast.LENGTH_SHORT).show();
}
}
}
/*
* 初始化按键 分别为 接 打 拒接 挂 播视频
*/
private void initTextView() {
jie = (TextView) findViewById(R.id.frag_tv);
da = (TextView) findViewById(R.id.come_call);
jujie = (TextView) findViewById(R.id.bu_jie);
gua = (TextView) findViewById(R.id.gua);
shipin = (TextView) findViewById(R.id.shipin);
}
@Override
public void onClick(View v) {
switch (v.getId()) {
case R.id.frag_tv://接
try {
EMChatManager.getInstance().answerCall();
Toast.makeText(context, "接", Toast.LENGTH_SHORT).show();
} catch (EMNoActiveCallException e) {
e.printStackTrace();
} catch (EMNetworkUnconnectedException e) {
e.printStackTrace();
}
break;
case R.id.come_call://播打语音
try {
EMChatManager.getInstance().makeVoiceCall("asd");//测试好友
Toast.makeText(context, "播打语音", Toast.LENGTH_SHORT).show();
} catch (EMServiceNotReadyException e) {
e.printStackTrace();
}
break;
case R.id.bu_jie://不接
try {
EMChatManager.getInstance().rejectCall();
Toast.makeText(context, "不接", Toast.LENGTH_SHORT).show();
} catch (EMNoActiveCallException e) {
e.printStackTrace();
}
break;
case R.id.gua://挂
EMChatManager.getInstance().endCall();
Toast.makeText(context, "挂", Toast.LENGTH_SHORT).show();
break;
case R.id.shipin://拨打视频
try {
EMChatManager.getInstance().makeVideoCall("asd");
} catch (EMServiceNotReadyException e) {
e.printStackTrace();
}
break;
}
}
/**
* 设置通话状态监听
* @param listener
*/
private void talkState() {
EMChatManager.getInstance().addVoiceCallStateChangeListener(new EMCallStateChangeListener() {
@Override
public void onCallStateChanged(CallState callState, CallError error) {
switch (callState) {
case CONNECTING: // 正在连接对方
Log.i("talkState", "正在连接对方");
break;
case CONNECTED: // 双方已经建立连接
Log.i("talkState", "双方已经建立连接");
break;
case ACCEPTED: // 电话接通成功
callHelper.setRenderFlag(true);
Log.i("talkState", "电话接通成功");
break;
case DISCONNNECTED: // 电话断了
Log.i("talkState", "电话断了");
break;
default:
break;
}
}
});
}
}
没有找到相关结果
已邀请:
0 个回复