SurfaceViewRenderer to HMSVideoView

Why should you migrate?

  • HMSVideoView provides a better abstraction to render live video and handles edge cases like managing release and init state. Can prevent accidentally subscribing to video track more than once.
  • Has in-built support for zoom and pan
  • Has in-built support to intelligently subscribe to video of the correct resolution. (Auto-Simulcast)
  • All the new features will be developed on HMSVideoView and SurfaceViewRenderer will be deprecated.

Minimum Requirements

  • SDK version 2.5.3 or higher

To use HMSVideoView you'll need to migrate from SurfaceViewRenderer (if you are already using it to render live video), by downloading the dependency from Maven Central

Adding the HMSVideoView

build.gradle
dependencies { def hmsVersion = "x.x.x" implementation "live.100ms:video-view:$hmsVersion" // HMSVideoView }

Updating the layout

<o̶r̶g̶.̶W̶e̶b̶R̶T̶C̶.̶S̶u̶r̶f̶a̶c̶e̶V̶i̶e̶w̶R̶e̶n̶d̶e̶r̶e̶r̶ live.hms.videoview.HMSVideoView android:id="@+id/peerVideo" android:layout_width="match_parent" android:layout_height="wrap_content"/>

Initalising and adding video track

val hmsVideoTrack : HMSVideotrack = hmsPeer.videoTrack s̶u̶r̶f̶a̶c̶e̶V̶i̶e̶w̶.̶i̶n̶i̶t̶(̶S̶h̶a̶r̶e̶d̶E̶g̶l̶C̶o̶n̶t̶e̶x̶t̶.̶c̶o̶n̶t̶e̶x̶t̶,̶ ̶n̶u̶l̶l̶)̶ ̶h̶m̶s̶V̶i̶d̶e̶o̶T̶r̶a̶c̶k̶?̶.̶a̶d̶d̶S̶i̶n̶k̶(̶s̶u̶r̶f̶a̶c̶e̶V̶i̶e̶w̶)̶ hmsVideoView.addTrack(hmsVideoTrack)

Removing video track

h̶m̶s̶V̶i̶d̶e̶o̶T̶r̶a̶c̶k̶.̶r̶e̶m̶o̶v̶e̶S̶i̶n̶k̶(̶s̶u̶r̶f̶a̶c̶e̶V̶i̶e̶w̶)̶ ̶s̶u̶r̶f̶a̶c̶e̶V̶i̶e̶w̶.̶r̶e̶l̶e̶a̶s̶e̶(̶)̶ hmsVideoView.removeTrack()

Have a suggestion? Recommend changes ->

Was this helpful?

1234