Use the OpenTok audio fallback API to dynamically prioritize audio in response to network quality.
For conceptual information, see the audio fallback overview.
Notes:
PublisherKit.setAudioFallbackEnabled()
and PublisherKit.setAudioFallbackEnabled()
methods will be deprecated. Please use the
PublisherKit.publisherAudioFallbackEnabled()
method instead.
This topic includes the following sections:
To enable publisher audio fallback, call the
PublisherKit.Builder.publisherAudioFallbackEnabled()
function when creating the publisher.
// Enable publisher audio fallback
mPublisher = new Publisher.Builder(context)
.publisherAudioFallbackEnabled(true)
.build();
// Enable publisher audio fallback and disable subscriber audio fallback
mPublisher = new Publisher.Builder(context)
.publisherAudioFallbackEnabled(true)
.subscriberAudioFallbackEnabled(false)
.build();
// Enable subscriber audio fallback and disable publisher audio fallback
mPublisher = new Publisher.Builder(context)
.publisherAudioFallbackEnabled(false)
.subscriberAudioFallbackEnabled(true)
.build();
To enable and disable subscriber audio fallback (for all subscribers to the stream), call the
PublisherKit.Builder.subscriberAudioFallbackEnabled()
function 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.
When publisher audio fallback is enabled, callback methods of the
PublisherKit.VideoListener
are invoked for publisher audio fallback-related events:
PublisherKit.VideoListener.onVideoDisableWarning()
— Called when the Publisher determines that the stream quality has degraded and the video will be disabled if the quality degrades more.PublisherKit.VideoListener.onVideoDisableWarningLifted()
— Called when the Publisher determines that the stream quality has improved to the point at which the video being disabled is not an immediate risk.PublisherKit.VideoListener.onVideoDisabled()
— Called when the Publisher determines that the stream quality has degraded and the outgoing video transport has been disabled. Note: while the video is disabled, the Publisher still displays the publisher video (such as the camera image) in the publishing client's UI.PublisherKit.VideoListener.onVideoEnabled()
— Called with reason "quality" when the Publisher determines that the stream quality has improved and outgoing video transport has been re-enabled.For example the following code handles the related events (so that you can provide your own user interface notifications):
@Override
public void onVideoDisableWarning(PublisherKit publisher) {
// Custom action — for example, add custom UI notification
}
@Override
public void onVideoDisableWarningLifted(PublisherKit publisher) {
// Custom action — for example, remove custom UI notification
}
@Override
public void onVideoDisabled(PublisherKit publisher, String reason) {
// Custom action — for example, add custom UI notification
}
@Override
public void onVideoEnabled(PublisherKit subscriber, String reason) {
// Custom action — for example, remove custom UI notification
}
When subscriber audio fallback is enabled, callback methods of the
SubscriberKit.VideoListener
are invoked for subscriber audio fallback-related events:
SubscriberKit.VideoListener.onVideoDisableWarning()
— Called when the Subscriber determines that the stream quality has degraded and the video will be disabled if the quality degrades more.SubscriberKit.VideoListener.onVideoDisableWarningLifted()
— Called when the Subscriber determines that the stream quality has improved to the point at which the video being disabled is not an immediate risk.SubscriberKit.VideoListener.onVideoDisabled()
— Called when the Subscriber determines that the stream quality has degraded and the outgoing video transport has been disabled. Note: while the video is disabled, the Subscriber still displays the subscriber video (such as the camera image) in the publishing client's UI.SubscriberKit.VideoListener.onVideoEnabled()
— Called with reason "quality" when the Subscriber determines that the stream quality has improved and outgoing video transport has been re-enabled.For example the following code handles the related events (so that you can provide your own user interface notifications):
@Override
public void onVideoDisableWarning(SubscriberKit subscriber) {
// Custom action — for example, add custom UI notification
}
@Override
public void onVideoDisableWarningLifted(SubscriberKit subscriber) {
// Custom action — for example, remove custom UI notification
}
@Override
public void onVideoDisabled(SubscriberKit subscriber, String reason) {
// Custom action — for example, add custom UI notification
}
@Override
public void onVideoEnabled(SubscriberKit subscriber, String reason) {
// Custom action — for example, remove custom UI notification
}