How-to: Display a video stream to the end-user
  • 25 Apr 2023
  • 1 読む分
  • PDF

How-to: Display a video stream to the end-user

  • PDF

The content is currently unavailable in Ja - 日本語. You are viewing the default English version.
記事の要約

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()  
        }  
    }  
}

この記事は役に立ちましたか?