livekit / client-sdk-android

LiveKit SDK for Android
https://docs.livekit.io
Apache License 2.0
169 stars 68 forks source link

Resume remote participant video when app going background to foreground #302

Open mithunvaghela opened 10 months ago

mithunvaghela commented 10 months ago

I am developing a android app with video calling features using livekit android sdk. I am wonder if I know that how can i resume my app with running remote participant video.

Created incoming and outgoing calls notification, when user accept the call, I am generating an ongoing notification. If i click on ongoing call notification my video call should be resume. even I am putting my app in background using home and pick from recent. In this case local video working fine but remote video going freeze until I turn off/on from remote side.

I tried to manage video track with enable, but didn't achieved to resume remote video. videoCallViewModel.remoteParticipant?.let { it.getTrackPublication(Track.Source.CAMERA)?.let { pub -> Timber.d { "Remote ${pub.track?.rtcTrack?.enabled()}" } pub.track?.let { track -> attachRemoteVideo(track as VideoTrack) } } }

is there any method or trick to resume remote video when user come again on video call screen?

roshanaryal commented 7 months ago

@mithunvaghela facing the similar problem . Did you find any solution?

mithunvaghela commented 7 months ago

@mithunvaghela facing the similar problem . Did you find any solution?

Hi @roshanaryal to resolve this issue I have resume and pause the remote video and that solution working fine form e, please check this solution.

Activity state ` override fun onResume() { super.onResume() Timber.d { "onResume" } if (args.isCallOnGoing()) videoCallViewModel.resumeRemoteVideoTrack() }

override fun onPause() {
    super.onPause()
    Timber.d { "onPause" }
    if (args.isCallOnGoing()) {
        videoCallViewModel.pauseRemoteVideoTrack()
    }
} `

ViewModel methods

` fun resumeRemoteVideoTrack() { viewModelScope.launch { val videoTrack = remoteParticipant?.let { return@let getVideoTrack(it) } videoTrack?.start() mutableRemoteVideoTrack.postValue(videoTrack) } }

fun pauseRemoteVideoTrack() {
    viewModelScope.launch {
        val videoTrack = remoteParticipant?.let { return@let getVideoTrack(it) }
        videoTrack?.stop()
        mutableRemoteVideoTrack.postValue(videoTrack)
    }
}

private fun getVideoTrack(participant: Participant): VideoTrack? {
    return participant.getTrackPublication(Track.Source.CAMERA)?.track as? VideoTrack
}`

Hope this solution will work for you as well. :)

davidliu commented 7 months ago

By any chance are you folks using compose with VideoRenderer or just using the SurfaceViewRenderer/TextureViewRenderer directly?

roshanaryal commented 7 months ago

@davidliu I am using TextureViewRenderer directly in xml . i am using participant in recyclerview , if i notifydatasetchanged on activity resume , video will resume otherwise it will freeze.

davidliu commented 7 months ago

I'm not able to repro this. Could you upload a small example project that repros this?

roshanaryal commented 7 months ago

@davidliu If you have some kind of timer running there and if that is updating text in every second or short interval...after pausing ...and resuming the screen video will not render automatically.

`private var liveStreamTimerUpdatingJob: Timer? = null private fun updateCreationTimer() { liveStreamTimerUpdatingJob?.cancel() liveStreamTimerUpdatingJob = null liveStreamTimerUpdatingJob = Timer() updateTimerText() } private fun updateTimerText() { liveStreamTimerUpdatingJob?.scheduleAtFixedRate( object :TimerTask(){ override fun run() { val elapsedTime = System.currentTimeMillis() - jyotishItem.creationTime mutableTimerText.postValue(TimerUtils.getFormattedTime(elapsedTime)) }

        },1000,1000)

}`

viewModel.timerText.observe(this) { binding.timerText.text = it }

I am using timer like this when i update text with this timer video rendering problem will occor on resume. I have tested by adding timer code on example project but getting same issue.