简体   繁体   English

图片InPicture模式后重新打开本地surfaceViewRenderer android

[英]Reopen local surfaceViewRenderer after pictureInPicture mode android

I have implemented a webRtc android application with kotlin.我已经使用 kotlin 实现了 webRtc android 应用程序。 I have created a class LocalParticipant and inside there i have a function that starts the camera and audio streams我创建了一个 class LocalParticipant 并且在里面我有一个 function 可以启动相机和音频流

private var eglBaseContext: EglBase.Context = EglBase.create().eglBaseContext
private var peerConnectionFactory: PeerConnectionFactory? = null
private var surfaceTextureHelper: SurfaceTextureHelper? = null

private var audioSource: AudioSource? = null
private var videoSource: VideoSource? = null
private var videoCapturer: VideoCapturer? = null

fun initAudioSource(): AudioSource? {
        if (audioSource == null) audioSource = peerConnectionFactory!!.createAudioSource(MediaConstraints())
        return audioSource
    }

    fun initAudioTrack(): AudioTrack? {
        return peerConnectionFactory?.let {
            audioTrack = it.createAudioTrack("101", it.createAudioSource(MediaConstraints()))
            audioTrack
        }
    }

    fun initVideoSource(): VideoSource? {
        if (videoSource == null) {
            if (videoCapturer == null)
                videoCapturer = createCameraCapturer()
            videoSource = peerConnectionFactory?.createVideoSource(videoCapturer!!.isScreencast)
        }
        return videoSource
    }

    fun initVideoTrack(videoHeader: VideoHeader): VideoTrack? {
        if (videoTrack == null) {
            videoCapturer?.initialize(surfaceTextureHelper, context, videoSource?.capturerObserver)
            videoCapturer?.startCapture(videoHeader.width, videoHeader.height, videoHeader.fps)
            videoTrack = peerConnectionFactory?.createVideoTrack("100", videoSource)
        }
        return videoTrack
    }

    fun addLocalSink() {
        videoTrack?.removeSink(localVideoView)
        videoTrack?.addSink(localVideoView)
    }

    fun setUpVideoSource(videoHeader: VideoHeader) {
        peerConnectionFactory?.let {
            surfaceTextureHelper = SurfaceTextureHelper.create("CaptureThread", eglBaseContext)
            initVideoSource()
            initVideoTrack(videoHeader)
            addLocalSink()
        }
    }

    fun startLocalParticipantTracks(videoHeader: VideoHeader) {
        peerConnectionFactory = session.peerConnectionFactory ?: return
        initAudioSource()
        initAudioTrack()
        if (videoHeader.hasVideo == 1) setUpVideoSource(videoHeader)
    }

In order to start the whole proccess so that the localParticipant can see himself i call the startLocalParticipantTracks from the ViewModel.为了启动整个过程以便 localParticipant 可以看到自己,我从 ViewModel 调用startLocalParticipantTracks Everything works fine.一切正常。
So now, i want to implement the PictureInPictureMode.所以现在,我想实现 PictureInPictureMode。 When i press the home button the localParticipantContainer view gets hidden.当我按下主页按钮时,localParticipantContainer 视图被隐藏。 But i open back again the application window the preview does not load so i see nothing, although that the remoteParticipants keep on see me live on camera.但是我再次打开应用程序 window 预览没有加载所以我什么也看不到,尽管远程参与者继续看到我在相机上直播。

On Exit from PipMode i call only the localParticipant.addLocalSink What else should i do?从 PipMode 退出时,我只调用localParticipant.addLocalSink我还应该做什么?

Try calling when you open the app again:再次打开应用时尝试拨打电话:

videoCapturer?.startCapture(videoHeader.width, videoHeader.height, videoHeader.fps)
 

This will start video(video capturer) source again这将再次启动视频(视频捕获器)源

Problem solved.问题解决了。 The issue was that I was not passing the new surfaceViewRenderer because the activity is recreated.问题是我没有通过新的surfaceViewRenderer,因为重新创建了活动。 So i had to pass the new view所以我不得不通过新观点

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 PictureInPicture模式Activity生命周期问题 - PictureInPicture mode Activity lifecycle problem 此操作之后无法重新打开Android App。 - unable to reopen Android App after this.finish() 旋转设备后重新打开Android对话框 - Android Dialog reopen after rotate device 如何在Android中的SurfaceViewRenderer上呈现WebRTC VideoTrack? - How to render WebRTC VideoTrack on SurfaceViewRenderer in Android? glReadPixels在WebRTC Android SurfaceViewRenderer中不起作用 - glReadPixels does not work in WebRTC Android SurfaceViewRenderer 如何在 webrtc org.webrtc.SurfaceViewRenderer 中调用 SurfaceViewRenderer.pauseVideo() 后恢复视频 - How to resume a video after calling SurfaceViewRenderer.pauseVideo() In webrtc org.webrtc.SurfaceViewRenderer Android:屏幕截图为 org.webrtc.SurfaceViewRenderer 获取黑色图像 - Android: Screen shot get black image for org.webrtc.SurfaceViewRenderer android 2.3.3 模拟器 - moveTasToBack(true) 和重新打开后的 classnotfoundexception - android 2.3.3 emulator - classnotfoundexception after moveTasToBack(true) and reopen 关闭并重新打开Android上的应用后,GPS无法更新位置 - GPS not update location after close and reopen app on android 如何在按下主页按钮并重新打开应用程序后在Android中恢复MediaPlayer - How to resume MediaPlayer in Android after pressing the home button and reopen the app
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM