Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.

public final class GoogleCast

  1. Object
  2. Cast
  3. 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.ProviderA 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

provider GoogleCast.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

url String
the media URL, reachable from the receiver
contentType String
the MIME type, such as video/mp4
title String
the title the receiver shows, or null
subtitle String
the second line the receiver shows, or null
imageUrl String
artwork, or null
startMillis long
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

millis long
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