Class GoogleCast

java.lang.Object
com.codename1.media.Cast
com.codename1.media.GoogleCast

public final class GoogleCast extends Cast

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();
  • 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: the provider, or null to remove it
    • isSupported

      public boolean isSupported()
      Description copied from class: Cast

      Answers whether this kind of route works on this device.

      Returns

      true when the route picker can be shown

      Overrides:
      isSupported in class Cast
    • showRoutePicker

      public boolean showRoutePicker()
      Description copied from class: Cast

      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

      Overrides:
      showRoutePicker in class Cast
    • isSessionActive

      public boolean isSessionActive()
      Description copied from class: Cast

      Answers whether a session to a device is up.

      Returns

      true while connected

      Overrides:
      isSessionActive in class Cast
    • load

      public boolean load(String url, String contentType, String title, String subtitle, String imageUrl, long startMillis)
      Description copied from class: Cast

      Asks the receiver to load and play a URL.

      Parameters
      • url: the media URL, reachable from the receiver

      • contentType: the MIME type, such as video/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)

      Overrides:
      load in class Cast
    • play

      public boolean play()
      Description copied from class: Cast

      Resumes playback on the receiver.

      Returns

      false when there is no remote session

      Overrides:
      play in class Cast
    • pause

      public boolean pause()
      Description copied from class: Cast

      Pauses playback on the receiver.

      Returns

      false when there is no remote session

      Overrides:
      pause in class Cast
    • seek

      public boolean seek(long millis)
      Description copied from class: Cast

      Seeks on the receiver.

      Parameters
      • millis: the position
      Returns

      false when there is no remote session

      Overrides:
      seek in class Cast
    • stop

      public boolean stop()
      Description copied from class: Cast

      Stops playback and ends the session.

      Returns

      false when there is no remote session

      Overrides:
      stop in class Cast