Class Cast
- Direct Known Subclasses:
GoogleCast
Sends media to a TV or speaker: discovers routes, shows the route picker and controls the remote session.
#getPlatform() is the route the platform has without extra libraries:
AirPlay on iOS, through the system route picker. With AirPlay the device
keeps playing the media itself and streams it to the route, so
#load(String, String, String, String, String, long) answers false there
and the app plays through MediaManager as usual. GoogleCast is the
Chromecast session, where the receiver fetches and plays the URL itself.
Unlike the static device services (PictureInPicture, Battery), this is
an instance API: a device can have more than one kind of route at once --
AirPlay and Google Cast on the same iPhone -- each with its own session and
state, so each kind is an object of its own with its own listeners.
Cast cast = Cast.getPlatform();
if (cast.isSupported()) {
cast.showRoutePicker();
}
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final intA Google Cast (Chromecast) session.static final intThe platform route: AirPlay on iOS.static final intA session is up and nothing is playing.static final intA session is starting.static final intNo session.static final intThe receiver is paused.static final intThe receiver is playing. -
Method Summary
Modifier and TypeMethodDescriptionvoidaddStateListener(SuccessCallback<Integer> listener) Adds a listener for session state changes; it receives aSTATE_constant on the EDT.intgetKind()The kind of route this instance controls.static CastThe platform route, AirPlay on iOS.intgetState()The last session state a port reported.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.voidremoveStateListener(SuccessCallback<Integer> listener) Removes a listener added with#addStateListener(SuccessCallback).booleanseek(long millis) Seeks on the receiver.static voidsetImplementation(com.codename1.impl.CodenameOneImplementation impl) Invoked internally from Display, this method is for internal use onlybooleanShows the system route picker, where the user discovers and picks a device.booleanstop()Stops playback and ends the session.
-
Field Details
-
KIND_PLATFORM
public static final int KIND_PLATFORMThe platform route: AirPlay on iOS.- See Also:
-
KIND_GOOGLE_CAST
public static final int KIND_GOOGLE_CASTA Google Cast (Chromecast) session.- See Also:
-
STATE_NO_SESSION
public static final int STATE_NO_SESSIONNo session.- See Also:
-
STATE_CONNECTING
public static final int STATE_CONNECTINGA session is starting.- See Also:
-
STATE_CONNECTED
public static final int STATE_CONNECTEDA session is up and nothing is playing.- See Also:
-
STATE_PLAYING
public static final int STATE_PLAYINGThe receiver is playing.- See Also:
-
STATE_PAUSED
public static final int STATE_PAUSEDThe receiver is paused.- See Also:
-
-
Method Details
-
setImplementation
public static void setImplementation(com.codename1.impl.CodenameOneImplementation impl) Invoked internally from Display, this method is for internal use only
Parameters
impl: implementation instance
-
getPlatform
The platform route, AirPlay on iOS.
Returns
the shared instance
-
getKind
public int getKind()The kind of route this instance controls.
Returns
KIND_PLATFORMorKIND_GOOGLE_CAST -
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: 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
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: 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
-
getState
public int getState()The last session state a port reported.
Returns
one of the
STATE_constants -
addStateListener
Adds a listener for session state changes; it receives a
STATE_constant on the EDT.Parameters
listener: the listener
-
removeStateListener
Removes a listener added with
#addStateListener(SuccessCallback).Parameters
listener: the listener
-