MediaRouteButton

fun MediaRouteButton(modifier: Modifier = Modifier, routeSelector: MediaRouteSelector = MediaRouteSelector.EMPTY, colors: IconButtonColors = IconButtonDefaults.iconButtonColors(), mediaRouteChooserDialog: @Composable (onDismissRequest: () -> Unit) -> Unit = { onDismissRequest -> MediaRouteChooserDialog( routeSelector = routeSelector, onDismissRequest = onDismissRequest, ) }, mediaRouteDynamicChooserDialog: @Composable (onDismissRequest: () -> Unit) -> Unit = mediaRouteChooserDialog, mediaRouteControllerDialog: @Composable (onDismissRequest: () -> Unit) -> Unit = { onDismissRequest -> MediaRouteControllerDialog( routeSelector = routeSelector, onDismissRequest = onDismissRequest, ) }, mediaRouteDynamicControllerDialog: @Composable (onDismissRequest: () -> Unit) -> Unit = mediaRouteControllerDialog, onDialogTypeChange: (dialogType: DialogType) -> Unit = {}, permissionDeniedDialog: @Composable (onDismissRequest: () -> Unit) -> Unit = { onDismissRequest -> PermissionDeniedDialog(onDismissRequest = onDismissRequest) })

The media route button allows the user to select routes and to control the currently selected route.

The application must specify the kinds of routes that the user should be allowed to select by specifying a selector.

When the default route is selected, the button will appear in an inactive state indicating that the application is not connected to a route. Clicking on the button opens a MediaRouteChooserDialog to allow the user to select a route. If no non-default routes match the selector, and it is not possible for an active scan to discover any matching routes, then the button is disabled.

When a non-default route is selected, the button will appear in an active state indicating that the application is connected to a route of the kind that it wants to use. The button may also appear in an intermediary connecting state if the route is in the process of connecting to the destination but has not yet completed doing so. In either case, clicking on the button opens a MediaRouteControllerDialog to allow the user to control or disconnect from the current route.

Starting with Android 17, discovering Cast devices requires the ACCESS_LOCAL_NETWORK runtime permission. If your application targets Android 17 or later and declares this permission in its manifest, clicking on the button requests it, if needed. If the permission is denied, a PermissionDeniedDialog is shown instead of the other dialogs.

This dialog can be customized with the permissionDeniedDialog parameter, for example to change its texts:

MediaRouteButton(
routeSelector = routeSelector,
permissionDeniedDialog = { onDismissRequest ->
PermissionDeniedDialog(
message = stringResource(R.string.local_network_permission_denied),
buttonText = stringResource(R.string.grant_permission),
onDismissRequest = onDismissRequest,
)
},
)

You can also provide your own composable. In that case, make sure to call onDismissRequest when the dialog is dismissed.

Parameters

modifier

The Modifier to be applied to this button.

routeSelector

The media route selector for filtering the routes that the user can select using the media route chooser dialog.

colors

IconButtonColors that will be used to resolve the colors used for this icon button in different states. See IconButtonDefaults.iconButtonColors.

mediaRouteChooserDialog

The media route chooser dialog. The provided callback should be called when the dialog has to be dismissed.

mediaRouteDynamicChooserDialog

The media route chooser dialog for dynamic group.

mediaRouteControllerDialog

The media route controller dialog. The provided callback should be called when the dialog has to be dismissed.

mediaRouteDynamicControllerDialog

The media route controller dialog for dynamic group.

onDialogTypeChange

The callback used to notify when the dialog type has changed.

permissionDeniedDialog

The dialog shown when the local network permission was denied. The provided callback should be called when the dialog has to be dismissed.