Class ChromeCast
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfinal voidconnect()final voidfinal Stringfinal Stringfinal Stringfinal Stringfinal MediaStatusIf no application is running at the moment then exception is thrown.final StringgetModel()final StringgetName()final intgetPort()final Applicationfinal Statusfinal StringgetTitle()final booleanisAppAvailable(String appId) final booleanisAppRunning(String appId) booleanfinal booleanfinal Applicationfinal MediaStatusLoads and starts playing media in specified URLfinal MediaStatusLoads and starts playing specified mediafinal MediaStatusLoads and starts playing specified mediafinal voidpause()Pause current playbackfinal voidplay()Resume paused media playbackfinal voidfinal voidfinal voidseek(double time) Moves current playback time point to specified valuefinal voidSends some generic request to the currently running application.final <T extends Response>
TSends some generic request to the currently running application.final voidsetApplication(String application) final voidsetAppsURL(String appsURL) voidsetAutoReconnect(boolean autoReconnect) Changes behaviour for opening/closing of connection with ChromeCast device.final voidsetMuted(boolean muted) final voidvoidsetRequestTimeout(long requestTimeout) Set up how much time to wait until request is processed (in milliseconds).final voidsetVolume(float level) final voidsetVolumeByIncrement(float level) ChromeCast does not allow you to jump levels too quickly to avoid blowing speakers.final voidstopApp()Stops currently running applicationfinal voidstopSession(String sessionId) Stops the session with the given identifier.final StringtoString()final voidfinal void
-
Field Details
-
SERVICE_TYPE
- See Also:
-
-
Constructor Details
-
ChromeCast
-
ChromeCast
-
-
Method Details
-
getName
- Returns:
- The technical name of the device. Usually something like Chromecast-e28835678bc02247abcdef112341278f.
-
setName
-
getAddress
- Returns:
- The IP address of the device.
-
getPort
public final int getPort()- Returns:
- The TCP port number that the device is listening to.
-
getAppsURL
-
setAppsURL
-
getApplication
- Returns:
- The mDNS service name. Usually "googlecast".
- See Also:
-
setApplication
-
getTitle
- Returns:
- The name of the device as entered by the person who installed it. Usually something like "Living Room Chromecast".
-
getAppTitle
- Returns:
- The title of the app that is currently running, or empty string in case of the backdrop. Usually something like "YouTube" or "Spotify", but could also be, say, the URL of a web page being mirrored.
-
getModel
- Returns:
- The model of the device. Usually "Chromecast" or, if Chromecast is built into your TV, the model of your TV.
-
connect
- Throws:
IOExceptionGeneralSecurityException
-
disconnect
- Throws:
IOException
-
isConnected
public final boolean isConnected() -
setAutoReconnect
public void setAutoReconnect(boolean autoReconnect) Changes behaviour for opening/closing of connection with ChromeCast device. If set to "true" (default value) then connection will be re-established on every request in case it is not present yet, or has been lost. "false" value means manual control over connection with ChromeCast device, i.e. callingconnect()ordisconnect()methods when needed.- Parameters:
autoReconnect- true means controlling connection with ChromeCast device automatically, false - manually- See Also:
-
isAutoReconnect
public boolean isAutoReconnect()- Returns:
- current value of
autoReconnectsetting, which controls opening/closing of connection with ChromeCast device - See Also:
-
setRequestTimeout
public void setRequestTimeout(long requestTimeout) Set up how much time to wait until request is processed (in milliseconds).- Parameters:
requestTimeout- value in milliseconds until request times out waiting for response
-
getStatus
- Returns:
- current chromecast status - volume, running applications, etc.
- Throws:
IOException
-
getRunningApp
- Returns:
- descriptor of currently running application
- Throws:
IOException
-
isAppAvailable
- Parameters:
appId- application identifier- Returns:
- true if application is available to this chromecast device, false otherwise
- Throws:
IOException
-
isAppRunning
- Parameters:
appId- application identifier- Returns:
- true if application with specified identifier is running now
- Throws:
IOException
-
launchApp
- Parameters:
appId- application identifier- Returns:
- application descriptor if app successfully launched, null otherwise
- Throws:
IOException
-
stopApp
Stops currently running application
If no application is running at the moment then exception is thrown.
- Throws:
IOException
-
stopSession
Stops the session with the given identifier.
- Parameters:
sessionId- session identifier- Throws:
IOException
-
setVolume
- Parameters:
level- volume level from 0 to 1 to set- Throws:
IOException
-
setVolumeByIncrement
ChromeCast does not allow you to jump levels too quickly to avoid blowing speakers. Setting by increment allows us to easily get the level we want- Parameters:
level- volume level from 0 to 1 to set- Throws:
IOException- See Also:
-
setMuted
- Parameters:
muted- is to mute or not- Throws:
IOException
-
getMediaStatus
If no application is running at the moment then exception is thrown.
- Returns:
- current media status, state, time, playback rate, etc.
- Throws:
IOException
-
play
Resume paused media playback
If no application is running at the moment then exception is thrown.
- Throws:
IOException
-
pause
Pause current playback
If no application is running at the moment then exception is thrown.
- Throws:
IOException
-
seek
Moves current playback time point to specified value
If no application is running at the moment then exception is thrown.
- Parameters:
time- time point between zero and media duration- Throws:
IOException
-
load
Loads and starts playing media in specified URL
If no application is running at the moment then exception is thrown.
- Parameters:
url- media url- Returns:
- The new media status that resulted from loading the media.
- Throws:
IOException
-
load
public final MediaStatus load(String mediaTitle, String thumb, String url, String contentType) throws IOException Loads and starts playing specified media
If no application is running at the moment then exception is thrown.
- Parameters:
mediaTitle- name to be displayedthumb- url of video thumbnail to be displayed, relative to media urlurl- media urlcontentType- MIME content type- Returns:
- The new media status that resulted from loading the media.
- Throws:
IOException
-
load
Loads and starts playing specified media
If no application is running at the moment then exception is thrown.
- Parameters:
media- The media to load and play. See https://developers.google.com/cast/docs/reference/messages#Load for more details.- Returns:
- The new media status that resulted from loading the media.
- Throws:
IOException
-
send
public final <T extends Response> T send(String namespace, Request request, Class<T> responseClass) throws IOException Sends some generic request to the currently running application.
If no application is running at the moment then exception is thrown.
- Type Parameters:
T- type of response- Parameters:
namespace- request namespacerequest- request objectresponseClass- class of the response for proper deserialization- Returns:
- deserialized response
- Throws:
IOException
-
send
Sends some generic request to the currently running application. No response is expected as a result of this call.
If no application is running at the moment then exception is thrown.
- Parameters:
namespace- request namespacerequest- request object- Throws:
IOException
-
registerListener
-
unregisterListener
-
registerConnectionListener
-
unregisterConnectionListener
-
toString
-