Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public final 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 types
interface GoogleCast.Provider | A platform Google Cast implementation. |
Methods
public static GoogleCast getInstance() | The Google Cast session controller. |
public static void setProvider(GoogleCast.Provider provider) | Registers the platform provider. |
public boolean isSupported() | Answers whether this kind of route works on this device. |
public boolean showRoutePicker() | Shows the system route picker, where the user discovers and picks a device. |
public boolean isSessionActive() | Answers whether a session to a device is up. |
public boolean load(String url, String contentType, String title, String subtitle, String imageUrl, long startMillis) | Asks the receiver to load and play a URL. |
public boolean play() | Resumes playback on the receiver. |
public boolean pause() | Pauses playback on the receiver. |
public boolean seek(long millis) | Seeks on the receiver. |
public boolean stop() | Stops playback and ends the session. |
Inherited fields
Inherited methods
Method details
getInstance
public static GoogleCast getInstance()The Google Cast session controller.
Returns
the shared instance
setProvider
public static void setProvider(GoogleCast.Provider provider)Registers the platform provider. Internal: for ports and generated code,
which inject the platform implementation here; applications do not call it.
Parameters
providerGoogleCast.Provider- the provider, or null to remove it
isSupported
public boolean isSupported()Answers whether this kind of route works on this device.
Returns
true when the route picker can be shown
showRoutePicker
public boolean showRoutePicker()Shows 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
isSessionActive
public boolean isSessionActive()Answers whether a session to a device is up.
Returns
true while connected
load
public boolean load(String url, String contentType, String title, String subtitle, String imageUrl, long startMillis)Asks the receiver to load and play a URL.
Parameters
urlString- the media URL, reachable from the receiver
contentTypeString- the MIME type, such as
video/mp4 titleString- the title the receiver shows, or null
subtitleString- the second line the receiver shows, or null
imageUrlString- artwork, or null
startMillislong- the position to start at
Returns
false when there is no session or the route plays locally (AirPlay)
play
public boolean play()Resumes playback on the receiver.
Returns
false when there is no remote session
pause
public boolean pause()Pauses playback on the receiver.
Returns
false when there is no remote session
seek
public boolean seek(long millis)Seeks on the receiver.
Parameters
millislong- the position
Returns
false when there is no remote session
stop
public boolean stop()Stops playback and ends the session.
Returns
false when there is no remote session