WearUnsuitableOutputPlaybackSuppressionResolverListener


@UnstableApi
class WearUnsuitableOutputPlaybackSuppressionResolverListener : 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

const 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!,
    autoResumeTimeoutMs: @IntRange(from = 0) Long
)

Creates a new instance.

Public functions

Unit
onEvents(player: Player!, events: Player.Events!)

Called when one or more player states changed.

Inherited functions

From androidx.media3.common.Player.Listener
Unit

Called when the value of getAudioAttributes changes.

Unit

Called when the audio session ID changes.

Unit

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

Unit
onCues(cueGroup: CueGroup!)

Called when the value of getCurrentCues changes.

Unit

This function is deprecated.

Use onCues instead.

Unit

Called when the device information changes

Unit
onDeviceVolumeChanged(volume: Int, muted: Boolean)

Called when the value of getDeviceVolume or isDeviceMuted changes.

Unit

Called when the player starts or stops loading the source.

Unit

Called when the value of isPlaying changes.

Unit

This function is deprecated.

Use onIsLoadingChanged instead.

Unit
onMaxSeekToPreviousPositionChanged(maxSeekToPreviousPositionMs: Long)

Called when the value of getMaxSeekToPreviousPosition changes.

Unit

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

Unit

Called when the value of getMediaMetadata changes.

Unit

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

Unit
onPlayWhenReadyChanged(
    playWhenReady: Boolean,
    @Player.PlayWhenReadyChangeReason reason: Int
)

Called when the value returned from getPlayWhenReady changes.

Unit

Called when the value of getPlaybackParameters changes.

Unit

Called when the value returned from getPlaybackState changes.

Unit

Called when the value returned from getPlaybackSuppressionReason changes.

Unit

Called when an error occurs.

Unit

Called when the PlaybackException returned by getPlayerError changes.

Unit
@UnstableApi
onPlayerStateChanged(
    playWhenReady: Boolean,
    @Player.State playbackState: Int
)

This function is deprecated.

Use onPlaybackStateChanged and onPlayWhenReadyChanged instead.

Unit

Called when the value of getPlaylistMetadata changes.

Unit

This function is deprecated.

Use onPositionDiscontinuity instead.

Unit
onPositionDiscontinuity(
    oldPosition: Player.PositionInfo!,
    newPosition: Player.PositionInfo!,
    @Player.DiscontinuityReason reason: Int
)

Called when a position discontinuity occurs.

Unit

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.

Unit

Called when the value of getRepeatMode changes.

Unit
onSeekBackIncrementChanged(seekBackIncrementMs: Long)

Called when the value of getSeekBackIncrement changes.

Unit
onSeekForwardIncrementChanged(seekForwardIncrementMs: Long)

Called when the value of getSeekForwardIncrement changes.

Unit
onShuffleModeEnabledChanged(shuffleModeEnabled: Boolean)

Called when the value of getShuffleModeEnabled changes.

Unit
onSkipSilenceEnabledChanged(skipSilenceEnabled: Boolean)

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

Unit
onSurfaceSizeChanged(width: Int, height: Int)

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

Unit
onTimelineChanged(
    timeline: Timeline!,
    @Player.TimelineChangeReason reason: Int
)

Called when the value of getCurrentTimeline changes.

Unit

Called when the value returned from getTrackSelectionParameters changes.

Unit

Called when the value of getCurrentTracks changes.

Unit

Called each time when getVideoSize changes.

Unit

Called when the value of getVolume changes.

Constants

DEFAULT_PLAYBACK_SUPPRESSION_AUTO_RESUME_TIMEOUT_MS

const val DEFAULT_PLAYBACK_SUPPRESSION_AUTO_RESUME_TIMEOUT_MSLong

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

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

WearUnsuitableOutputPlaybackSuppressionResolverListener(
    context: Context!,
    autoResumeTimeoutMs: @IntRange(from = 0) Long
)

Creates a new instance.

Parameters
context: Context!

Any context.

autoResumeTimeoutMs: @IntRange(from = 0) Long

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 functions

onEvents

fun onEvents(player: Player!, events: Player.Events!): Unit

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.

events: Player.Events!

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