[英]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.