CastButtonFactory

public final classCastButtonFactoryextendsObject

A factory class to set up aMenuItemor a MediaRouteButton to be used as a Cast button. The SDK will set aMediaRouteSelector which is built by theCastContext, based on the discovery options set insideCastOptions.

Public Method Summary

static void
setUpMediaRouteButton(Context context, MediaRouteButton button)
Sets up the givenMediaRouteButton.
staticMenuItem
setUpMediaRouteButton(Context context,Menumenu, int menuResourceId)
Sets up theMediaRouteActionProvider inmenu.
static Task<Void>
setUpMediaRouteButton(Context context,Executor executor, MediaRouteButton button)
Sets up the givenMediaRouteButton with an asynchronous call, which will not block the caller thread.
static Task<MenuItem>
setUpMediaRouteButton(Context context,Executor executor,Menumenu, int menuResourceId)
Sets up theMediaRouteActionProvider inmenuwith an asynchronous call, which will not block the caller thread.

Inherited Method Summary

Public Methods

public static voidsetUpMediaRouteButton(Contextcontext, MediaRouteButton button)

Sets up the givenMediaRouteButton.

Parameters
context The applicationContext.
button TheMediaRouteButton instance to set up.
Throws
IllegalStateException If this method is not called on the main thread.

public staticMenuItem setUpMediaRouteButton(Contextcontext, Menumenu, int menuResourceId)

Sets up theMediaRouteActionProvider inmenu.Returns theMenuItemof theMediaRouteActionProvider.

Parameters
context The applicationContext.
menu Menu reference.
menuResourceId The resource id of the cast button in the xml menu descriptor file.
Throws
IllegalArgumentException Ifmenudoesn't contain a menu item with menuResourceIdidentifier, or the menu item doesn't have a MediaRouteActionProvider.
IllegalStateException If this method is not called on the main thread.

public static Task<Void>setUpMediaRouteButton(Contextcontext, Executor executor, MediaRouteButton button)

Sets up the givenMediaRouteButton with an asynchronous call, which will not block the caller thread.

Note that ModuleUnavailableExceptioncould be thrown when the SDK fails to load the internal Cast module. The caller will get the exception fromTask.getException() when the task completes.

Parameters
context The applicationContext.
executor AnExecutor to load the internal Cast module if needed.
button TheMediaRouteButton instance to set up.
Throws
IllegalStateException If this method is not called on the main thread.

public static Task<MenuItem> setUpMediaRouteButton(Contextcontext, Executor executor,Menumenu, int menuResourceId)

Sets up theMediaRouteActionProvider inmenuwith an asynchronous call, which will not block the caller thread. Returns theMenuItemof theMediaRouteActionProvider.

Note that ModuleUnavailableExceptioncould be thrown when the SDK fails to load the internal Cast module. The caller will get the exception fromTask.getException() when the task completes.

Parameters
context The applicationContext.
executor AnExecutor to load the internal Cast module if needed.
menu Menu reference.
menuResourceId The resource id of the cast button in the xml menu descriptor file.
Throws
IllegalArgumentException Ifmenudoesn't contain a menu item with menuResourceIdidentifier, or the menu item doesn't have a MediaRouteActionProvider.
IllegalStateException If this method is not called on the main thread.