Suggestions

close search

Add Messaging, Voice, and Authentication to your apps with Vonage Communications APIs

Visit the Vonage API Developer Portal

Audio Fallback — iOS (Swift)

Use the OpenTok audio fallback API to dynamically prioritize audio in response to network quality.

For conceptual information, see the audio fallback overview.

Notes:

  • The audioFallbackEnabled property of OTPublisherKit will be deprecated. Please use the subscriberAudioFallbackEnabled property of OTPublisherKitSettings instead.

This topic includes the following sections:

Enabling and disabling audio-only fallback

To enable publisher audio fallback, set the OTPublisherKitSettings.publisherAudioFallbackEnabled property when creating the publisher.


// Enable publisher audio fallback
let publisherSettings = OTPublisherSettings()
publisherSettings.publisherAudioFallbackEnabled = YES

// Enable publisher audio fallback and disable subscriber audio fallback
let publisherSettings = OTPublisherSettings()
publisherSettings.publisherAudioFallbackEnabled = YES
publisherSettings.subscriberAudioFallbackEnabled = NO

// Enable subscriber audio fallback and disable publisher audio fallback
let publisherSettings = OTPublisherSettings()
publisherSettings.publisherAudioFallbackEnabled = NO
publisherSettings.subscriberAudioFallbackEnabled = YES

To enable and disable subscriber audio fallback (for all subscribers to the stream), set the OTPublisherKitSettings.subscriberAudioFallbackEnabled property when creating the publisher. Subscriber audio fallback is only supported in routed sessions (sessions that use the OpenTok Media Router). Subscriber audio fallback is enabled by default (in routed sessions) for streams with a camera video source.

Publisher audio fallback events

When publisher audio fallback is enabled, the PublisherKitDelegate object will send the following messages pertaining to publisher audio fallback-related events:

For example the following code handles the related events (so that you can provide your own user interface notifications):


func publisherVideoDisableWarning(_ publisher: OTPublisherKit) {
  // Custom action — for example, add custom UI notification
}

func publisherVideoDisableWarningLifted(_ publisher: OTPublisherKit) {
  // Custom action — for example, remove custom UI notification
}

func publisherVideoDisabled(_ publisher: OTPublisherKit, reason: OTPublisherVideoEventReason) {
  // Custom action — for example, add custom UI notification
}

func publisherVideoEnabled(_ publisher: OTPublisherKit, reason: OTPublisherVideoEventReason) {
  // Custom action — for example, remove custom UI notification
}

Subscriber audio fallback events

When subscriber audio fallback is enabled, the SubscriberKitDelegate object will send the following messages pertaining to subscriber audio fallback-related events:

For example the following code handles the related events (so that you can provide your own user interface notifications):


func subscriberVideoDisableWarning(_ subscriber: OTSubscriberKit) {
  // Custom action — for example, add custom UI notification
}

func subscriberVideoDisableWarningLifted(_ subscriber: OTSubscriberKit) {
  // Custom action — for example, remove custom UI notification
}

func subscriberVideoDisabled(_ subscriber: OTSubscriberKit, reason: OTSubscriberVideoEventReason) {
  // Custom action — for example, add custom UI notification
}

func subscriberVideoEnabled(_ subscriber: OTSubscriberKit, reason: OTSubscriberVideoEventReason) {
  // Custom action — for example, remove custom UI notification
}