Reputation: 312
I'm trying to create a WebRTC app, based in webrtc-android-codelab. I have a WebView and when I want to make a video call I start an activity and establish a video call, it's working but I can't hangup the video call and return to previous activity. If I close or dispose the peerconnection I get the following error:
"Native thread exiting without having called DetachCurrentThread (maybe it's going to use a pthread_key_create destructor?)".
And if I call finish() in hangup() to leave the activity, the app crashes with the following error:
"E/UncaughtException: java.lang.RuntimeException: Unable to destroy activity This object has been released".
This is my hangup code:
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;
}
Upvotes: 4
Views: 1463
Reputation: 312
It's working now with this code:
private void hangup() {
try {
localPeer.close();
localPeer = null;
updateVideoViews(false);
SignallingClient.getInstance().isInitiator=false;
SignallingClient.getInstance().isChannelReady=false;
SignallingClient.getInstance().isStarted=false;
finish();
} catch (Exception e) {
e.printStackTrace();
}
}
Upvotes: 1