Client API. The Codename One framework your app is built on: this runs on the device, not in a backend.
public class Cast
- Object
- Cast
Known subtypesGoogleCast
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();
}Fields
public static final int KIND_PLATFORM = 0 | The platform route: AirPlay on iOS. |
public static final int KIND_GOOGLE_CAST = 1 | A Google Cast (Chromecast) session. |
public static final int STATE_NO_SESSION = 0 | No session. |
public static final int STATE_CONNECTING = 1 | A session is starting. |
public static final int STATE_CONNECTED = 2 | A session is up and nothing is playing. |
public static final int STATE_PLAYING = 3 | The receiver is playing. |
public static final int STATE_PAUSED = 4 | The receiver is paused. |
Methods
Inherited methods
Field details
KIND_PLATFORM
public static final int KIND_PLATFORM = 0KIND_GOOGLE_CAST
public static final int KIND_GOOGLE_CAST = 1STATE_NO_SESSION
public static final int STATE_NO_SESSION = 0STATE_CONNECTING
public static final int STATE_CONNECTING = 1STATE_CONNECTED
public static final int STATE_CONNECTED = 2STATE_PLAYING
public static final int STATE_PLAYING = 3STATE_PAUSED
public static final int STATE_PAUSED = 4Method details
setImplementation
public static void setImplementation(CodenameOneImplementation impl)Parameters
implCodenameOneImplementation- implementation instance
getPlatform
public static Cast getPlatform()Returns
getKind
public int getKind()Returns
KIND_PLATFORM or KIND_GOOGLE_CASTisSupported
public boolean isSupported()Returns
showRoutePicker
public boolean showRoutePicker()Returns
isSessionActive
public boolean isSessionActive()Returns
load
public boolean load(String url, String contentType, String title, String subtitle, String imageUrl, long startMillis)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
play
public boolean play()Returns
pause
public boolean pause()Returns
seek
public boolean seek(long millis)Parameters
millislong- the position
Returns
stop
public boolean stop()Returns
getState
public int getState()Returns
STATE_ constantsaddStateListener
public void addStateListener(SuccessCallback<Integer> listener)STATE_
constant on the EDT.Parameters
listenerSuccessCallback<Integer>- the listener
removeStateListener
public void removeStateListener(SuccessCallback<Integer> listener)#addStateListener(SuccessCallback).Parameters
listenerSuccessCallback<Integer>- the listener