2

Forgive me if this question was already asked, I couldn't find an answer for my case.

So, I have an Android app with Voice & Video call feature. I used webRTC for this.

I was able to make both Voice and Video call working perfectly inside an Activity, but now I want to keep the call running while the user exit the CallActivity and go back to the ChatActivity (to send a file/link/photo for example).

I managed to make the Voice call run perfectly inside a Background Service, but video call won't work as expected.

The remote video won't be displayed even though the audio from the video track is playing.

here is my Background Service code :

@Override
        public void onAddStream(MediaStream mediaStream) {
            if (mediaStream.videoTracks.size() > Constants.ONE || mediaStream.audioTracks.size() > Constants.ONE) {
                return;
            }

            //check for video track, means this is a video call
            if (!isAudioCall && mediaStream.videoTracks.size() > Constants.ZERO) {
                remoteVideoTrack = mediaStream.videoTracks.get(Constants.ZERO);
                CallActivityNew.remoteVideoTrack = remoteVideoTrack;
                try {
                    localAudioTrack.setEnabled(true);

                    //Now ask the UI to display the video track
                    sendOrderToActivity(Constants.START_REMOTE_VIDEO, null);
                } catch (Exception ignored) {}
            } else if (mediaStream.audioTracks.size() > Constants.ZERO) {
                //Means this is a Voice call, only audio tracks available
                remoteAudioTrack = mediaStream.audioTracks.get(Constants.ZERO);
                try {
                    localAudioTrack.setEnabled(true);
                    remoteAudioTrack.setEnabled(true);
                } catch (Exception ignored) {}
            }
        }

and below my CallActivity code :

case Constants.START_REMOTE_VIDEO: {
                if (remoteVideoView == null) {
                    remoteVideoView = findViewById(R.id.remote_gl_surface_view);
                }
                remoteVideoView.init(eglBaseContext, null);
                remoteVideoView.setEnableHardwareScaler(true);
                remoteVideoView.setMirror(true);
                remoteVideoView.setScalingType(RendererCommon.ScalingType.SCALE_ASPECT_FIT);
                remoteVideoView.setZOrderMediaOverlay(true);

                //Apply video track to the Surface View in order to display it
                remoteVideoTrack.addSink(remoteVideoView);

                //now enable local video track
                Handler handler = new Handler();
                handler.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        //now enable local video track
                        remoteVideoTrack.setEnabled(true);
                    }
                }, Constants.TIME_THREE_HUNDRED_MILLIS);

                setSpeakerphoneOn(false);
                break;
            }

I am sending orders from Service to Activity, the "case Constants.START_REMOTE_VIDEO" work after receiving the order from Service.

I don't see where the problem, why am I only hearing sound but the remote video won't start display !!

Thank you in advance for helping.

OussaMah
  • 817
  • 9
  • 19

1 Answers1

1

After testing for long hours, I found that my code works just fine, I just forget to change the view visibility from "GONE" to "VISIBLE". Yeah that was the solution, i swear xD

OussaMah
  • 817
  • 9
  • 19
  • 1
    Frankly, I'm having a very similar issue ;) Could you elaborate more on what view you are talking about? – Vasniktel Mar 12 '20 at 15:39
  • Hi there. I was talking about the "remoteVideoView" which is defined inside the layout (xml) file. The one we link with the remoteVideoTrack using the addSink() function. – OussaMah Mar 13 '20 at 16:19
  • Are you using the openVidu server for the gideo call? – james04 Mar 07 '21 at 17:50
  • For testing, i was using the free google webrtc servers. Then I used TwilioSDK for Android, it is a paid service, with stable servers and easy usage. – OussaMah Mar 08 '21 at 12:33
  • my setting SCALE_ASPECT_FIT not working, it's still FILL, can. u help? – famfamfam Mar 13 '21 at 07:46
  • Are you using WebView for the WebRTC? I'm having the same problem with WebView. – user1801605 Jul 08 '21 at 23:16
  • Long time since i worked on this, but, from what I remember, I didn't have any WebView. I was developpping native code in Java. – OussaMah Jul 15 '21 at 13:59
  • Hey @OussaMah, I am having the same issue (particularly making the call to still go on in the background) could you share as more code snippet or an opensource repo I could check. Thanks in advance – Patrick Waweru Jan 10 '22 at 04:52
  • Hey @PatrickWaweru, for the webRtc calls, I was working on a private project (more than 2 years ago now), and I can't share the code. The idea is to put the webRTC code into an Android service, a background service with a foreground persistent notification so the code could keep running. – OussaMah Jan 17 '22 at 12:39