How-to: Display a video stream to the end-user
- 25 Apr 2023
- 1 Minute to read
- Print
- DarkLight
- PDF
How-to: Display a video stream to the end-user
- Updated on 25 Apr 2023
- 1 Minute to read
- Print
- DarkLight
- PDF
Article summary
Did you find this summary helpful?
Thank you for your feedback
It is recommended to use the helper VideoView class to simplify the interaction with video tracks in the SDK.
Example:
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.screenmeet.live.R
import com.screenmeet.live.databinding.FragmentVideoBinding
import com.screenmeet.live.util.viewBinding
import com.screenmeet.sdk.Participant
import com.screenmeet.sdk.ScreenMeet
import com.screenmeet.sdk.SessionEventListener
import com.screenmeet.sdk.VideoElement
import org.webrtc.EglBase
class VideoFragment: Fragment(R.layout.fragment_video) {
private val binding by viewBinding(FragmentVideoBinding::bind)
private lateinit var eglBase: EglBase.Context
override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
// Register EglBase context object in your Fragment
eglBase = ScreenMeet.eglContext!!
// Prepare your custom VideoView for rendering
binding.videoViewRenderer.init(eglBase, null)
}
override fun onResume() {
super.onResume()
// Subscribe to session events
ScreenMeet.registerEventListener(eventListener)
// Restore Video Rendering
ScreenMeet.uiVideos().firstOrNull()?.let {
binding.activeStreamRenderer.zoomRenderer.render(it.track)
}
}
override fun onPause() {
super.onPause()
// Unsubscribe from session events
ScreenMeet.unregisterEventListener(eventListener)
// Clear Video Renderer
binding.activeStreamRenderer.zoomRenderer.clear()
}
private val eventListener = object : SessionEventListener {
override fun onParticipantVideoCreated(
participant: Participant,
video: VideoElement
) {
// Start rendering a new video
binding.activeStreamRenderer.zoomRenderer.render(video.track)
}
override fun onParticipantVideoStopped(
participant: Participant,
source: ScreenMeet.VideoSource
) {
// Clear Video Renderer
binding.activeStreamRenderer.zoomRenderer.clear()
}
}
}
Was this article helpful?