如果觉得下面的麻烦可以直接到https://item.taobao.com/item.htm?id=587133228080获取源码。源码功能性更好、更完善。
想测试apk请加群261074724
最新的sdk4教程地址 https://blog.csdn.net/Java_lilin/article/details/84842314
前面两篇介绍了注册、拨打、接听等 参考地址https://me.csdn.net/java_lilin
一.拨打视频通话
1.创建VideoActivity.java 并且在AndroidManifest.xml配置
package com.lilin.mylinephone;
。。。
import android.view.SurfaceView;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class VideoActivity extends Activity implements OnClickListener{
private VideoActivityReceiver mReceiver;
public static final String RECEIVE_VIDEO_ACTIVITY = "receive_video_activity";
private SurfaceView mRenderingView,mPreviewView;
private AndroidVideoWindowImpl mAndroidVideoWindow;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_video);
init();
//广播
IntentFilter intentFilter = new IntentFilter(RECEIVE_VIDEO_ACTIVITY);
mReceiver = new VideoActivityReceiver();
registerReceiver(mReceiver, intentFilter);
fixZOrder(mRenderingView, mPreviewView);
mAndroidVideoWindow = new AndroidVideoWindowImpl(mRenderingView, mPreviewView, new AndroidVideoWindowImpl.VideoWindowListener() {
public void onVideoRenderingSurfaceReady(AndroidVideoWindowImpl vw, SurfaceView surface) {
mRenderingView = surface;
LinphoneMiniManager.getLC().setVideoWindow(vw);
}
public void onVideoRenderingSurfaceDestroyed(AndroidVideoWindowImpl vw) {
LinphoneCore linphoneCore = LinphoneMiniManager.getLC();
if (linphoneCore != null) {
linphoneCore.setVideoWindow(null);
}
}
public void onVideoPreviewSurfaceReady(AndroidVideoWindowImpl vw, SurfaceView surface) {
mPreviewView = surface;
LinphoneMiniManager.getLC().setPreviewWindow(mPreviewView);
}
public void onVideoPreviewSurfaceDestroyed(AndroidVideoWindowImpl vw) {
LinphoneMiniManager.getLC().setPreviewWindow(null);
}
});
}
private void init() {
((Button) findViewById(R.id.id_video_gua)).setOnClickListener(this);
((Button) findViewById(R.id.id_video_mute)).setOnClickListener(this);
((Button) findViewById(R.id.id_video_speaker)).setOnClickListener(this);
((Button) findViewById(R.id.id_video_qiev)).setOnClickListener(this);
mRenderingView = (SurfaceView) findViewById(R.id.id_video_rendering);
mPreviewView = (SurfaceView) findViewById(R.id.id_video_preview);
}
@Override
protected void onResume() {
super.onResume();
if (mRenderingView != null) {
((GLSurfaceView) mRenderingView).onResume();
}
if (mAndroidVideoWindow != null) {
synchronized (mAndroidVideoWindow) {
LinphoneMiniManager.getLC().setVideoWindow(mAndroidVideoWindow);
}
}
}
@Override
protected void onPause() {
super.onPause();
if (mAndroidVideoWindow != null) {
synchronized (mAndroidVideoWindow) {
LinphoneMiniManager.getLC().setVideoWindow(null);
}
}
if (mRenderingView != null) {
((GLSurfaceView) mRenderingView).onPause();
}
}
@Override
protected void onDestroy() {
super.onDestroy();
if (mReceiver != null) {
unregisterReceiver(mReceiver);
}
mPreviewView = null;
mRenderingView = null;
if (mAndroidVideoWindow != null) {
mAndroidVideoWindow.release();
mAndroidVideoWindow = null;
}
}
public class VideoActivityReceiver extends BroadcastReceiver {
@Override
public void onReceive(Context context, Intent intent) {
String action = intent.getStringExtra("action");
switch (action) {
case "end":
VideoActivity.this.finish();
break;
default:
break;
}
}
}
@Override
public void onClick(View view) {
LinphoneMiniManager instance = LinphoneMiniManager.getInstance();
switch (view.getId()) {
case R.id.id_video_gua:
instance.hangUp();
finish();
break;
case R.id.id_video_mute:
break;
case R.id.id_video_speaker:
break;
case R.id.id_video_qiev:
switchCamera(instance);
break;
default:
break;
}
}
}
3. 在原来的MainActivity.java的xml添加一个按钮用于拨打
<Button
android:layout_width="wrap_content"
android:layout_marginTop="5dip"
android:layout_height="wrap_content"
android:id="@+id/id_btn_vda"
android:text="视频拨打"
/>
MainActivity.java添加启动的
case R.id.id_btn_vda:
try {
instance.lilin_call(id_etext_dail.getText().toString(),host,true);
startActivity(new Intent(MainActivity.this, VideoActivity.class));
} catch (LinphoneCoreException e1) {Log.e("MainActivity", e1.getMessage());}
break;
好了 现在就可以拨打视频了 挂断的需要发送广播接受
在LinphoneMiniManager.java添加
@Override
public void displayStatus(LinphoneCore lc, String message) {
Log.e("lilin displayStatus: "+message );
if(message.indexOf("Call terminated")!=-1){
Intent intent = new Intent(VideoActivity.RECEIVE_VIDEO_ACTIVITY);
intent.putExtra("action", "end");
sendBroadcast( intent);
}
}
好了 上面的就可以进行拨打视频通话了
二、接受视频通话
可以在接电话按钮中添加
case R.id.id_btn_jie:
try {
instance.lilin_jie();
if(instance.lilin_getVideoEnabled()) {//启动视频
startActivity(new Intent(MainActivity.this, VideoActivity.class));
}
} catch (LinphoneCoreException e) {Log.e("MainActivity", e.getMessage()); }
并在LinphoneMiniManager.java添加
public boolean lilin_getVideoEnabled() {
LinphoneCallParams remoteParams = mLinphoneCore.getCurrentCall().getRemoteParams();
return remoteParams != null && remoteParams.getVideoEnabled();
}
public void hangUp() {
LinphoneCall currentCall = mLinphoneCore.getCurrentCall();
if (currentCall != null) {
mLinphoneCore.terminateCall(currentCall);
} else if (mLinphoneCore.isInConference()) {
mLinphoneCore.terminateConference();
} else {
mLinphoneCore.terminateAllCalls();
}
}
public void updateCall() {
LinphoneCall lCall = mLinphoneCore.getCurrentCall();
if (lCall == null) {
Log.e("Trying to updateCall while not in call: doing nothing");
return;
}
mLinphoneCore.updateCall(lCall,null);
}
好了 所有的基本功能都已经实现了 其他的例如编码等需参考源码的写法
对此感兴趣的可以加群261074724