# SessionAvailabilityListener

Artifact: [androidx.media3:media3-cast](https://developer.android.com/jetpack/androidx/releases/media3) [View Source](https://cs.android.com/search?q=file:androidx/media3/cast/SessionAvailabilityListener.java+class:androidx.media3.cast.SessionAvailabilityListener)

*** ** * ** ***


```
@UnstableApi
interface SessionAvailabilityListener
```

<br />

*** ** * ** ***

Listener of changes in the cast session availability.

## Summary

| ### Nested types |
|---|
| `@https://developer.android.com/reference/kotlin/androidx/annotation/IntDef(value = ) @https://developer.android.com/reference/java/lang/annotation/Documented.html @https://developer.android.com/reference/java/lang/annotation/Retention.html(value = https://developer.android.com/reference/java/lang/annotation/RetentionPolicy.html#SOURCE) @https://developer.android.com/reference/java/lang/annotation/Target.html(value = https://developer.android.com/reference/java/lang/annotation/ElementType.html#TYPE_USE) annotation https://developer.android.com/reference/kotlin/androidx/media3/cast/SessionAvailabilityListener.SessionUnavailableReason` Reasons for the Cast session becoming unavailable. |

| ### Constants |
|---|---|
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/cast/SessionAvailabilityListener#SESSION_UNAVAILABLE_REASON_APP_STOPPED() = 3` The Cast receiver application was stopped. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/cast/SessionAvailabilityListener#SESSION_UNAVAILABLE_REASON_DISCONNECTED() = 4` The Cast session was disconnected. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/cast/SessionAvailabilityListener#SESSION_UNAVAILABLE_REASON_ROUTE_CHANGED() = 1` Playback is transferring to the local device because the route was changed. |
| `const https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/cast/SessionAvailabilityListener#SESSION_UNAVAILABLE_REASON_STOPPED() = 2` The user explicitly stopped casting. |

| ### Public functions |
|---|---|
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/cast/SessionAvailabilityListener#onCastSessionAvailable()()` Called when a cast session becomes available to the player. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/cast/SessionAvailabilityListener#onCastSessionUnavailable()()` Called when the cast session becomes unavailable. |
| `https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-unit/index.html` | `https://developer.android.com/reference/kotlin/androidx/media3/cast/SessionAvailabilityListener#onCastSessionUnavailable(int)( @https://developer.android.com/reference/kotlin/androidx/media3/cast/SessionAvailabilityListener.SessionUnavailableReason reason: https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/-int/index.html )` Called when the cast session becomes unavailable with the specified reason. |

## Constants

### SESSION_UNAVAILABLE_REASON_APP_STOPPED

```
const val SESSION_UNAVAILABLE_REASON_APP_STOPPED = 3: Int
```

The Cast receiver application was stopped.

### SESSION_UNAVAILABLE_REASON_DISCONNECTED

```
const val SESSION_UNAVAILABLE_REASON_DISCONNECTED = 4: Int
```

The Cast session was disconnected.

### SESSION_UNAVAILABLE_REASON_ROUTE_CHANGED

```
const val SESSION_UNAVAILABLE_REASON_ROUTE_CHANGED = 1: Int
```

Playback is transferring to the local device because the route was changed.

### SESSION_UNAVAILABLE_REASON_STOPPED

```
const val SESSION_UNAVAILABLE_REASON_STOPPED = 2: Int
```

The user explicitly stopped casting.

## Public functions

### onCastSessionAvailable

```
fun onCastSessionAvailable(): Unit
```

Called when a cast session becomes available to the player.

### onCastSessionUnavailable

```
fun onCastSessionUnavailable(): Unit
```

Called when the cast session becomes unavailable. This only gets called if onCastSessionUnavailable(@CastPlayer.CastSessionChangeReason int reason) is not implemented

### onCastSessionUnavailable

```
fun onCastSessionUnavailable(
    @SessionAvailabilityListener.SessionUnavailableReason reason: Int
): Unit
```

Called when the cast session becomes unavailable with the specified reason. The reason can affect the player state transfer. For example, a "Stop Casting" button press or a disconnection typically require the playback to pause.