Class GoogleCast
A Google Cast (Chromecast) session.
On Android the build registers a Google Cast provider when the app
references this class, and adds the Cast framework dependency for it.
Elsewhere no provider is registered, so #isSupported() answers false
and the app should fall back to Cast#getPlatform().
final Cast cast = GoogleCast.getInstance();
cast.addStateListener(new SuccessCallback<Integer>() {
public void onSucess(Integer state) {
if (state.intValue() == Cast.STATE_CONNECTED) {
cast.load("https://example.com/movie.mp4", "video/mp4", "Movie", null, null, 0);
}
}
});
cast.showRoutePicker();
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic interfaceA platform Google Cast implementation. -
Field Summary
Fields inherited from class Cast
KIND_GOOGLE_CAST, KIND_PLATFORM, STATE_CONNECTED, STATE_CONNECTING, STATE_NO_SESSION, STATE_PAUSED, STATE_PLAYING -
Method Summary
Modifier and TypeMethodDescriptionstatic GoogleCastThe Google Cast session controller.booleanAnswers whether a session to a device is up.booleanAnswers whether this kind of route works on this device.booleanload(String url, String contentType, String title, String subtitle, String imageUrl, long startMillis) Asks the receiver to load and play a URL.booleanpause()Pauses playback on the receiver.booleanplay()Resumes playback on the receiver.booleanseek(long millis) Seeks on the receiver.static voidsetProvider(GoogleCast.Provider provider) Registers the platform provider.booleanShows the system route picker, where the user discovers and picks a device.booleanstop()Stops playback and ends the session.Methods inherited from class Cast
addStateListener, getKind, getPlatform, getState, removeStateListener, setImplementation
-
Method Details
-
getInstance
The Google Cast session controller.
Returns
the shared instance
-
setProvider
Registers the platform provider. Internal: for ports and generated code, which inject the platform implementation here; applications do not call it.
Parameters
provider: the provider, or null to remove it
-
isSupported
public boolean isSupported()Description copied from class:CastAnswers whether this kind of route works on this device.
Returns
true when the route picker can be shown
- Overrides:
isSupportedin classCast
-
showRoutePicker
public boolean showRoutePicker()Description copied from class:CastShows the system route picker, where the user discovers and picks a device. On iOS this is best effort: there is no public call that opens the AirPlay picker, so the port taps the button inside the system's route picker view, and answers false when it finds none.
Returns
false when the picker cannot be shown here
- Overrides:
showRoutePickerin classCast
-
isSessionActive
public boolean isSessionActive()Description copied from class:CastAnswers whether a session to a device is up.
Returns
true while connected
- Overrides:
isSessionActivein classCast
-
load
public boolean load(String url, String contentType, String title, String subtitle, String imageUrl, long startMillis) Description copied from class:CastAsks the receiver to load and play a URL.
Parameters
-
url: the media URL, reachable from the receiver -
contentType: the MIME type, such asvideo/mp4 -
title: the title the receiver shows, or null -
subtitle: the second line the receiver shows, or null -
imageUrl: artwork, or null -
startMillis: the position to start at
Returns
false when there is no session or the route plays locally (AirPlay)
-
-
play
-
pause
-
seek
-
stop
-