Einstellungen für Abonnenten
Übersicht
Die Vonage Video Client SDKs ermöglichen es den Teilnehmern, Audio und Video in einer Sitzung zu abonnieren. Die Client-SDKs ermöglichen die Konfiguration des Subscriber-Objekts auf der Grundlage Ihrer Präferenzen und Ihres Anwendungsfalls.
In dieser Anleitung wird das Thema behandelt:
- Nur Audio- oder Videoabonnements
- Erkennen, ob ein Stream Audio oder Video enthält
- Ändern der Videoeinstellungen eines Teilnehmers
- Ändern der Audioeinstellungen eines Teilnehmers
Nur Audio- oder Video-Abonnement
Wenn Sie einen Stream abonnierenkönnen Sie angeben, ob Sie zunächst den Audio- oder den Videostream abonnieren möchten (sofern verfügbar). Der folgende Code abonniert zum Beispiel nur den Audiostream:
<OTSubscriber
properties={{
subscribeToAudio: true,
subscribeToVideo: false,
}}
/>
var options = {subscribeToAudio:true, subscribeToVideo:false};
// Replace stream and replacementElementId with your own values:
subscriber = session.subscribe(stream,
replacementElementId,
options);
subscriber = OTSubscriber(stream: stream, delegate: self)
subscriber.subscribeToAudio = false
_subscriber = [[OTSubscriber alloc]
initWithStream:stream delegate:self];
_subscriber.subscribeToAudio = NO;
Nachdem Sie ein Subscriber-Objekt erstellt haben, schalten Sie den Ton ein oder aus, indem Sie die Funktion subscribeToAudio() Methode des Subscriber-Objekts:
subscriber.subscribeToAudio(false); // audio off
subscriber.subscribeToAudio(true); // audio on
mSubscriber.setSubscribeToAudio(false); // audio off
mSubscriber.setSubscribeToAudio(true); // audio on
subscriber.subscribeToAudio = false // audio off
subscriber.subscribeToAudio = true // audio on
_subscriber.subscribeToAudio = NO; // audio off
_subscriber.subscribeToAudio = YES; // audio on
subscriber.SubscribeToAudio = false; // audio off
subscriber.SubscribeToAudio = true; // audio on
// audio off:
otc_subscriber_set_subscribe_to_audio(subscriber, OTC_FALSE);
// audio on:
otc_subscriber_set_subscribe_to_audio(subscriber, OTC_TRUE);
// audio off:
otc_subscriber_set_subscribe_to_audio(subscriber, OTC_FALSE);
// audio on:
otc_subscriber_set_subscribe_to_audio(subscriber, OTC_TRUE);
Sie schalten das Video ein oder aus, indem Sie die Funktion subscribeToVideo() Methode des Subscriber-Objekts:
subscriber.subscribeToVideo(false); // video off
subscriber.subscribeToVideo(true); // video on
mSubscriber.setSubscribeToVideo(false); // video off
mSubscriber.setSubscribeToVideo(true); // video on
subscriber.subscribeToVideo = false // video off
subscriber.subscribeToVideo = true // video on
subscriber.subscribeToVideo = NO; // video off
subscriber.subscribeToVideo = YES; // video on
subscriber.SubscribeToVideo = false; // video off
subscriber.SubscribeToVideo = true; // video on
// audio off:
otc_subscriber_set_subscribe_to_video(subscriber, OTC_FALSE);
// audio on:
otc_subscriber_set_subscribe_to_video(subscriber, OTC_TRUE);
// audio off:
otc_subscriber_set_subscribe_to_video(subscriber, OTC_FALSE);
// audio on:
otc_subscriber_set_subscribe_to_video(subscriber, OTC_TRUE);
Beachten Sie jedoch, dass Sie Audio oder Video nur abonnieren können, wenn der Client, der den Stream veröffentlicht, Audio oder Video enthält. Zum Beispiel, der Aufruf subscribeToVideo(false) hat keine Auswirkung, wenn der Client, der den Stream veröffentlicht, nur Audio veröffentlicht.
Erkennen, ob ein Stream Audio oder Video enthält
Standardmäßig gibt ein Subscriber-Objekt sowohl Audio als auch Video wieder (wenn sie verfügbar sind). Sie können überprüfen, ob ein Stream Audio oder Video enthält (wenn der Herausgeber des Streams Audio oder Video streamt), indem Sie die hasAudio und hasVideo Eigenschaften des Stream-Objekts:
<OTSession
eventHandlers={{
streamCreated: event => {
console.log('Stream created -- stream ID:', event.streamId);
console.log('hasAudio:', event.hasAudio);
console.log('hasVideo:', event.hasVideo);
}
}}/>
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.
if (!stream.hasAudio) {
// You may want to adjust the user interface
}
if (!stream.hasVideo) {
// You may want to adjust the user interface
}
if (!mStream.hasAudio()) {
// You may want to adjust the user interface
}
if (!mStream.hasVideo()) {
// You may want to adjust the user interface
}
if !stream.hasAudio {
// You may want to adjust the user interface
}
if !stream.hasVideo {
// You may want to adjust the user interface
}
if (!stream.hasAudio) {
// You may want to adjust the user interface
}
if (!stream.hasVideo) {
// You may want to adjust the user interface
}
if (!stream.HasAudio) {
// You may want to adjust the user interface
}
if (!stream.HasVideo) {
// You may want to adjust the user interface
}
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.
Zum Beispiel, wenn Sie einen Stream abonnierenWenn Sie einen Stream mit Audio- oder Videofunktion haben, möchten Sie vielleicht die Benutzeroberfläche entsprechend anpassen. Zum Beispiel können Sie dem Benutzer anzeigen, ob ein Stream Audio hat oder nicht; oder Sie können einen Abonnenten nicht ausblenden, wenn ein Stream kein Video hat.
Erkennen, wenn ein Stream Audio oder Video hinzufügt oder entfernt
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:
<OTSession
eventHandlers={{
streamPropertyChanged: event => {
if (event.changedProperty === 'hasAudio')
// Adjust the UI for the subscriber to event.streamId.
} else if (event.changedProperty === 'hasVideo') {
// Adjust the UI for the subscriber to event.streamId.
}
}}/>
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:
session.on("streamPropertyChanged", function (event) {
var subscribers = session.getSubscribersForStream(event.stream);
for (var i = 0; i < subscribers.length; i++) {
// You may want to display some UI text for each
// subscriber, or make some other UI change,
// based on event.changedProperty and
// event.newValue
}
}
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.
Ändern der Videoeinstellungen eines Teilnehmers
Einstellen der Auflösung und Bildrate für ein Video
Sie können die Bildrate und Auflösung für den Stream eines Teilnehmers festlegen, indem Sie
die preferredFrameRate und preferredResolution Eigenschaften der Optionen, die Sie in der
session.subscribe() Methode. Wir empfehlen die Einstellung der preferredResolution
Option zu "auto" um die CPU- und Netzwerknutzung zu optimieren. Die "auto" ist eine Beta-Funktion. Siehe Einstellung der bevorzugten Bildrate und Auflösung
Ändern der Audioeinstellungen eines Teilnehmers
Umschalten des von einem Teilnehmer verwendeten Audioausgangs
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:
// Cycling through audio output devices
let currentIndex = 0;
const audioOutputs = await OT.getAudioOutputDevices();
const currentOutputDevice = await OT.getActiveAudioOutputDevice();
audioOutputs.forEach((device, index) => {
if (device.label === currentOutputDevice.label) {
currentIndex = index;
}
});
const cycleAudioOutput = async () => {
currentIndex += 1;
let deviceId = audioOutputs[currentIndex % audioOutputs.length].deviceId;
await OT.setAudioOutputDevice(deviceId);
};
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:
AudioDeviceManager.getAudioDevice().setOutputMode(
OutputMode.Handset);
Ändern des Audiopegels eines Teilnehmers
Wenn Sie einen Stream abonnierenkönnen Sie die Anfangslautstärke des Teilnehmers einstellen, wenn Sie die subscribe() Methode des Session-Objekts:
// Set a value between 0 (silent) and 100 (full volume):
var subOptions = {audioVolume = 10};
// Replace stream and replacementElementId with your own values:
subscriber = session.subscribe(stream,
replacementElementId,
subOptions);
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):
subscriber.setAudioVolume(0); (silent)
Note that the user can also mute the subscriber via user interface controls in the subscriber.
// Set a value between 0 (silent) and 100 (full volume):
var subOptions = {audioVolume = 10};
// Replace stream and replacementElementId with your own values:
subscriber = session.subscribe(stream,
replacementElementId,
subOptions);
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):
subscriber.setAudioVolume(0); (silent)
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.