我正在尝试创建一个基于webrtc-android-codelab的WebRTC应用程序。我有一个WebView,当我想要进行视频通话时,我会启动一个活动并建立视频通话,这是有效的,但我无法挂断视频通话并返回到先前的活动。如果我关闭或处理peerconnection,我会收到以下错误信息:“Native thread exiting without having called DetachCurrentThread (maybe it's going to use a pthread_key_create destructor?)”。如果我在hangup()中调用finish()离开活动,则应用程序会崩溃,并显示以下错误:“E/UncaughtException: java.lang.RuntimeException: Unable to destroy activity This object has been released”。这是我的挂断代码:
private void hangup() {
if (peerConnectionFactory != null) {
peerConnectionFactory.stopAecDump();
}
if(stream !=null) {
while(stream.audioTracks.size() > 0) {
AudioTrack audioTrack = stream.audioTracks.get(0);
stream.removeTrack(audioTrack);
}
while(stream.videoTracks.size() > 0) {
VideoTrack videoTrack = stream.videoTracks.get(0);
stream.removeTrack(videoTrack);
}
}
if (audioSource != null) {
audioSource.dispose();
audioSource = null;
}
if (videoCapturerAndroid != null) {
try {
videoCapturerAndroid.stopCapture();
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
videoCapturerAndroid.dispose();
videoCapturerAndroid = null;
}
if (videoSource != null) {
videoSource.dispose();
videoSource = null;
}
if(localPeer!=null) {
localPeer.close();
localPeer = null;
}
SignallingClient.getInstance().isInitiator=false;
SignallingClient.getInstance().isChannelReady=false;
SignallingClient.getInstance().isStarted=false;
}