Subscribing to other client streams
We want clients to be able to subscribe to (or view) other clients’ streams in the session:
- Add a
subscriberproperty to the MainActivity class (after the declaration of thepublisherproperty):
The Subscriber class is defined in the Android SDK. It defines an object that a client uses to subscribe to (view) a stream published by another client.
- Modify the implementation of the
onStreamReceived(session, stream)method (one of the SessionListener callbacks) to include code to subscribe to other clients’ streams the session:
- To log events Add
subscriberListenerproperty belowsessionListenerof theMainActivity:
When another client publishes a stream to a session, this method is called, and a Stream object is passed in. The Stream class is defined in the Android SDK, and it represents an audio-video stream in the session.
The code initializes an instance of the Subscriber class, defined in the Android SDK. The Subscriber.Builder() constructor takes two parameters:
- The Android application context associated with this process.
- The Stream object (for the stream you want to view)
The Session.subscribe(subscriber) method subscribes to the stream that was received.
subscriberViewContainer.addView(subscriber.getView()) places the new subscribed stream's view on the screen.
- Modify the implementation of the
onStreamDropped(Session session, Stream stream)method (another one of the SessionListener callbacks):
subscriberViewContainer.removeAllViews() removes a subscriber's view once the stream has dropped.
Basic video chat
Learn the basic concepts of the Vonage Video API platform, including how users can communicate through video, voice, and messaging. Explore a basic Vonage Video API flow.