【问题标题】:Android WebRTC can continue voice call, but can't continue video callAndroid WebRTC可以继续语音通话,但不能继续视频通话
【发布时间】:2018-06-09 00:59:43
【问题描述】:

我正在开发一个 Android 视频-音频通话应用程序,到目前为止,我已经完成了主要功能,它运行良好,我可以制作:语音通话、视频通话。我的问题是当我按下主页按钮时(视频因任何原因被中断)我无法再次恢复, 奇怪的是,我可以用声音做任何我需要的事情;在应用程序处于后台并停止语音时继续,但不幸的是我根本无法控制视频。我认为在创建与视频相关的 webRTC 内容时存在问题,因此这里是负责该问题的代码:

PeerConnectionFactory.initialize(PeerConnectionFactory.InitializationOptions
            .builder(this)
            .setEnableVideoHwAcceleration(true)
            .createInitializationOptions());


    PeerConnectionFactory.Options options = new PeerConnectionFactory.Options();

    DefaultVideoEncoderFactory defaultVideoEncoderFactory = new DefaultVideoEncoderFactory(rootEglBase.getEglBaseContext(),  true,  true);
    DefaultVideoDecoderFactory defaultVideoDecoderFactory = new DefaultVideoDecoderFactory(rootEglBase.getEglBaseContext());

    peerConnectionFactory = new PeerConnectionFactory(options, defaultVideoEncoderFactory,defaultVideoDecoderFactory);

    videoCapturerAndroid = createCameraCapturer(new Camera1Enumerator(false));

    audioConstraints = new MediaConstraints();
    videoConstraints = new MediaConstraints();

    //Create a VideoSource instance
    videoSource = peerConnectionFactory.createVideoSource(videoCapturerAndroid);
    localVideoTrack = peerConnectionFactory.createVideoTrack("100", videoSource);

    //create an AudioSource instance
    audioSource = peerConnectionFactory.createAudioSource(audioConstraints);
    localAudioTrack = peerConnectionFactory.createAudioTrack("101", audioSource);

    videoCapturerAndroid.startCapture(1024, 720, 30);

    localVideoView.setVisibility(View.VISIBLE);
    //create a videoRenderer based on SurfaceViewRenderer instance
    localRenderer = new VideoRenderer(localVideoView);

    localVideoTrack.addRenderer(localRenderer);

    gotUserMedia = true;

我会在需要时更新问题(即需要一些其他代码 sn-p)。 请帮忙,我已经尝试解决这个问题大约一个星期了,我取得的唯一进展是学习如何控制声音:) 提前谢谢你

【问题讨论】:

    标签: android webrtc


    【解决方案1】:

    我花了更多时间尝试这样做,终于成功了,这就是我所做的:

    我尝试在打开应用程序后检查 onResume() 中的流是否为空 再次从睡眠状态(睡眠意味着单击了主页按钮),但它不为空。之后我决定看看如果我在 onResume() 中再次显示流会发生什么(但我需要在显示它之前检查它是否为空,因为在我第一次打开应用程序时它将为空)。这就是我再次重用视频流所要做的一切,实际上这让我可以翻转相机(前后),因为在此之前我无法做到这一点。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-11-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-09-11
      • 2021-01-15
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多