The recent audio and video research is a bit excessive. . . . . .
Let me talk about the problems I encountered today
1. Click the button from page A to jump to the scanning QR code page. It can be successful for the first time. After entering the audio and video call page, hang up the video and scan again, and the message "failed to connect camera service" will appear. . It's really sad. It turns out that there is a VideoSource in webrtc that encapsulates camera resources, and I. . Not released. Soga Next, let's take a look at the webrtc resource release method I wrote. .
/***
* 处理挂断视频
* */
public void handleHangUp() {
if (null != videoChatCallback) {
videoChatCallback.onCloseWithUserId(GetGlassInfo.getInstance().getAppId());
videoChatCallback.onCloseLocalStream(localMediaStream, GetGlassInfo.getInstance().getAppId());
}
mWebconnectManager.closePeerConnection(GetGlassInfo.getInstance().getWebId());
if (null != localMediaStream) {
localMediaStream = null;
}
}
There are mainly two ways to
onCloseLocalStream This is mainly an activity callback. The main thing to do here is to remove the screen
if (null != localRender) {
VideoRendererGui.remove(localRender);
localRender = null;
}
finish();
The most important thing is the closePeerConnection method to see
public void closePeerConnection(String connectionId) {
Log.e("sssss", "peers==" + peers.toString() + "---connectionId==" + connectionId);
if (null != peers) {
//关闭peerconnecttion连接
Peer peer = peers.get(connectionId);
if (peer != null) {
PeerConnection connection = peer.pc;
if (connection != null) {
connection.close();
connection.dispose();
}
peers.remove(connectionId);
} else {
Log.e("ssssss", "peerc===null");
}
if (null != audioSource) {//释放音频资源
audioSource.dispose();
audioSource = null;
}
if (null != videoSource) {//释放视频资源
videoSource.dispose();
videoSource = null;
}
if (capture != null) {释放画面
capture.dispose();
capture = null;
}
if (null != factory) {//释放掉PeerConnecttionFactroy
factory.dispose();
factory = null;
}
}
}
The main thing here is to release resources. . .
And then. . .
In the activity of the video screen
@Override
protected void onPause() {
super.onPause();
Log.e("sssss", "onPause==" + isConnect);
if (glSurfaceView != null) {
glSurfaceView.onPause();
}
mWebSocketManager.stopVideoSource();
}
@Override
protected void onResume() {
super.onResume();
if (glSurfaceView != null) {
glSurfaceView.onResume();
}
mWebSocketManager.restartVideoSource();
}
Attach the method of stop and resume
private boolean isStop = false;
public void restartVideoSource() {
if (null != videoSource && isStop) {
videoSource.restart();
}
}
public void stopVideoSource() {
if (null != videoSource) {
Log.e("ssssss", "videoSource stop");
videoSource.stop();
isStop = true;
}
}
The above is the release of webrtc resources that have been tested so far. I hope I can remember it in the future. Aha, more content about webrtc android, let me talk slowly haha