Subscriber Settings
Overview
The Vonage Video Client SDKs allow for participants to subscribe to audio and video in a session. The Client SDKs allow for configuring the Subscriber object based on your preferences and use case.
This how-to will go over:
- Subscribing to audio or video only
- Detecting whether a stream has audio or video
- Changing a Subscriber's video settings
- Changing a Subscriber's audio settings
Subscribing to Audio or Video Only
When you subscribe to a stream, you can specify whether to initially subscribe to audio or video (if they are available). For example, the following code subscribes to the audio stream only:
After you create a Subscriber object, you toggle audio on or off by calling the subscribeToAudio() method of the Subscriber object:
You toggle video on or off by calling the subscribeToVideo() method of the Subscriber object:
Note however that you can only subscribe to audio or video if the client publishing the stream includes audio or video. For example, calling subscribeToVideo(false) will have no effect if the client publishing the stream is publishing audio only.
Detecting Whether a Stream Has Audio or Video
By default, a Subscriber object plays back both audio and video (if they are available). You can check if a stream has audio or video (if the publisher of the stream is streaming audio or video) by checking the hasAudio and hasVideo properties of the Stream object:
You may want to set state properties based on the hasAudio and hasVideo properties and adjust the UI for the OTSubscriber based on these state values. You may want to adjust the user interface based on whether the stream has audio or video. For example, you may want to indicate to the user whether a stream has audio or not; or you may not want to hide a subscriber if a stream does not have video.
You can call the otc_stream_has_audio() and otc_stream_has_audio() member functions of an otc_stream instance to see if it has audio or video.
You can call the otc_stream_has_audio() and otc_stream_has_audio() member functions of an otc_stream instance to see if it has audio or video.
For example, when you subscribe to a stream, you may want to adjust the user interface based on whether the stream has audio or video. For example, you may want to indicate to the user whether a stream has audio or not; or you may not want to hide a subscriber if a stream does not have video.
Detecting When a Stream Adds or Removes Audio or Video
The Session object dispatches a streamPropertyChanged event when a stream toggles audio or video on or off. The streamPropertyChanged event is defined by the StreamPropertyChangedEvent class. The event object has a changedProperty property (identifying the Stream property that changed) and a newValue property (the new value of the Stream property). For example, the following code listens for changes in an audio and video in a Stream:
Note that a subscriber's video can be disabled or enabled for reasons other than the publisher disabling or enabling it. A Subscriber object dispatches videoDisabled and videoEnabled events in all conditions that cause the subscriber's stream to be disabled or enabled. For details, see the documentation for the Subscriber videoDisabled and [Subscriber videoEnabled]https://vonage.github.io/video-docs/video-js-reference/latest/Subscriber.html#event:videoEnabled) events.
The OTSession object dispatches a streamPropertyChanged event when a stream toggles audio or video on or off. The event object has a changedProperty property set to hasAudio or hasVideo when the audio or video changes. The newValue property is set to a Boolean value. For example, the following code listens for changes in a audio and video in a Stream:
Changing a Subscriber’s Video Settings
Setting the Resolution and Frame Rate for a Video
You can set the frame rate and resolution for a subscriber's stream by setting the preferredFrameRate and preferredResolution properties of the options you pass into the session.subscribe() method. We recommend setting the preferredResolution option to "auto" to optimize the CPU and network usage. The "auto" option is a beta feature. See Setting the preferred frame rate and resolution
Changing a Subscriber’s Audio Settings
Switching the Audio Output Used by a Subscriber
You can switch the audio output device (a speaker or headphones) used to play audio from all publishers and subscribers (in all Vonage Video sessions in the browser).
The OT.getAudioOutputDevices() method enumerates the audio and video input devices available to the browser.
The OT.getActiveAudioOutputDevice() method identifies the currently active audio output device.
Use the OT.setAudioOutputDevice() method to set the audio output device.
For example, the following code shows you how to implement a cycleAudioOutput() function that cycles through the available audio output devices:
By default, the Android SDK uses the device loudspeaker (instead of the headset speaker) for playing audio. This is preferable for apps that include both video and audio. However, in a voice-only session, it is preferable to have the audio played back using the headset speaker. You can have the app do this by making the following call:
Changing the Audio Level of a Subscriber
When you subscribe to a stream, you can set the initial volume of the subscriber when you call the subscribe() method of the Session object:
After you create a Subscriber object, you can set its volume by calling its setAudioVolume() method, passing in a value from 0 (silent) to 100 (full volume):
Note that the user can also mute the subscriber via user interface controls in the subscriber.
After you create a Subscriber object, you can set its volume by calling its setAudioVolume() method, passing in a value from 0 (silent) to 100 (full volume):
Note that the user can also mute the subscriber via user interface controls in the subscriber.
You can individually set the audio volume for each subscriber by setting the OTSubscriberKit.audioVolume property.
You can individually set the audio volume for each subscriber by setting the OTSubscriberKit.audioVolume property.
You can individually set the audio volume for each subscriber by calling the Subscriber.AudioVolume property.
You can individually set the audio volume for each subscriber by calling the otc_subscriber_set_audio_volume() function.
You can individually set the audio volume for each subscriber by calling the otc_subscriber_set_audio_volume() function.