WearUnsuitableOutputPlaybackSuppressionResolverListener


@UnstableApi
public final class WearUnsuitableOutputPlaybackSuppressionResolverListener implements Player.Listener


A Player.Listener that launches a system dialog in response to PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT to allow the user to connect a suitable audio output. Also, it auto-resumes the playback when the playback suppression reason is changed from PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT to PLAYBACK_SUPPRESSION_REASON_NONE.

This listener only reacts to PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT on Wear OS devices, while being no-op for non-Wear OS devices.

The system dialog will be the Media Output Switcher if it is available on the device, or otherwise the Bluetooth settings screen.

This implementation also pauses playback when launching the system dialog. The underlying Player implementation (e.g. ExoPlayer) is expected to resume playback automatically when a suitable audio device is connected by the user.

Summary

Constants

static final long

The default timeout for auto-resume of suppressed playback when the playback suppression reason as PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT is removed, in milliseconds.

Public constructors

Creates a new instance.

WearUnsuitableOutputPlaybackSuppressionResolverListener(
    Context context,
    @IntRange(from = 0) long autoResumeTimeoutMs
)

Creates a new instance.

Public methods

void
onEvents(Player player, Player.Events events)

Called when one or more player states changed.

Inherited methods

From androidx.media3.common.Player.Listener
void

Called when the value of getAudioAttributes changes.

void

Called when the audio session ID changes.

void

Called when the value returned from isCommandAvailable changes for at least one Command.

void
onCues(CueGroup cueGroup)

Called when the value of getCurrentCues changes.

void

This method is deprecated.

Use onCues instead.

void

Called when the device information changes

void
onDeviceVolumeChanged(int volume, boolean muted)

Called when the value of getDeviceVolume or isDeviceMuted changes.

void
onIsLoadingChanged(boolean isLoading)

Called when the player starts or stops loading the source.

void
onIsPlayingChanged(boolean isPlaying)

Called when the value of isPlaying changes.

void
@UnstableApi
onLoadingChanged(boolean isLoading)

This method is deprecated.

Use onIsLoadingChanged instead.

void
onMaxSeekToPreviousPositionChanged(long maxSeekToPreviousPositionMs)

Called when the value of getMaxSeekToPreviousPosition changes.

void

Called when playback transitions to a media item or starts repeating a media item according to the current repeat mode.

void

Called when the value of getMediaMetadata changes.

void

Called when there is metadata associated with the current playback time.

void
onPlayWhenReadyChanged(
    boolean playWhenReady,
    @Player.PlayWhenReadyChangeReason int reason
)

Called when the value returned from getPlayWhenReady changes.

void

Called when the value of getPlaybackParameters changes.

void

Called when the value returned from getPlaybackState changes.

void

Called when the value returned from getPlaybackSuppressionReason changes.

void

Called when an error occurs.

void

Called when the PlaybackException returned by getPlayerError changes.

void
@UnstableApi
onPlayerStateChanged(
    boolean playWhenReady,
    @Player.State int playbackState
)

This method is deprecated.

Use onPlaybackStateChanged and onPlayWhenReadyChanged instead.

void

Called when the value of getPlaylistMetadata changes.

void

This method is deprecated.

Use onPositionDiscontinuity instead.

void
onPositionDiscontinuity(
    Player.PositionInfo oldPosition,
    Player.PositionInfo newPosition,
    @Player.DiscontinuityReason int reason
)

Called when a position discontinuity occurs.

void

Called when a frame is rendered for the first time since setting the surface, or since the renderer was reset, or since the stream being rendered was changed.

void

Called when the value of getRepeatMode changes.

void
onSeekBackIncrementChanged(long seekBackIncrementMs)

Called when the value of getSeekBackIncrement changes.

void
onSeekForwardIncrementChanged(long seekForwardIncrementMs)

Called when the value of getSeekForwardIncrement changes.

void
onShuffleModeEnabledChanged(boolean shuffleModeEnabled)

Called when the value of getShuffleModeEnabled changes.

void
onSkipSilenceEnabledChanged(boolean skipSilenceEnabled)

Called when skipping silences is enabled or disabled in the audio stream.

void
onSurfaceSizeChanged(int width, int height)

Called each time there's a change in the size of the surface onto which the video is being rendered.

void
onTimelineChanged(
    Timeline timeline,
    @Player.TimelineChangeReason int reason
)

Called when the value of getCurrentTimeline changes.

void

Called when the value returned from getTrackSelectionParameters changes.

void

Called when the value of getCurrentTracks changes.

void

Called each time when getVideoSize changes.

void
onVolumeChanged(float volume)

Called when the value of getVolume changes.

Constants

DEFAULT_PLAYBACK_SUPPRESSION_AUTO_RESUME_TIMEOUT_MS

public static final long DEFAULT_PLAYBACK_SUPPRESSION_AUTO_RESUME_TIMEOUT_MS

The default timeout for auto-resume of suppressed playback when the playback suppression reason as PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT is removed, in milliseconds.

Public constructors

WearUnsuitableOutputPlaybackSuppressionResolverListener

public WearUnsuitableOutputPlaybackSuppressionResolverListener(
    Context context
)

Creates a new instance.

See WearUnsuitableOutputPlaybackSuppressionResolverListener for more details. The auto-resume timeout defaults to DEFAULT_PLAYBACK_SUPPRESSION_AUTO_RESUME_TIMEOUT_MS.

Parameters
Context context

Any context.

WearUnsuitableOutputPlaybackSuppressionResolverListener

public WearUnsuitableOutputPlaybackSuppressionResolverListener(
    Context context,
    @IntRange(from = 0) long autoResumeTimeoutMs
)

Creates a new instance.

Parameters
Context context

Any context.

@IntRange(from = 0) long autoResumeTimeoutMs

Duration in milliseconds after the playback suppression during which playback will be resumed automatically if the playback suppression reason is changed from PLAYBACK_SUPPRESSION_REASON_UNSUITABLE_AUDIO_OUTPUT to PLAYBACK_SUPPRESSION_REASON_NONE. Calling with autoResumeTimeoutMs = 0 will cause playback to never resume automatically.

Public methods

onEvents

public void onEvents(Player player, Player.Events events)

Called when one or more player states changed.

State changes and events that happen within one Looper message queue iteration are reported together and only after all individual callbacks were triggered.

Listeners should prefer this method over individual callbacks in the following cases:

Parameters
Player player

The Player whose state changed. Use the getters to obtain the latest states.

Player.Events events

The Events that happened in this iteration, indicating which player states changed.