Class ChromeCast

java.lang.Object
su.litvak.chromecast.api.v2.ChromeCast

public class ChromeCast extends Object
ChromeCast device - main object used for interaction with ChromeCast dongle.
  • Field Details

  • Constructor Details

    • ChromeCast

      public ChromeCast(String address)
    • ChromeCast

      public ChromeCast(String address, int port)
  • Method Details

    • getName

      public final String getName()
      Returns:
      The technical name of the device. Usually something like Chromecast-e28835678bc02247abcdef112341278f.
    • setName

      public final void setName(String name)
    • getAddress

      public final String 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

      public final String getAppsURL()
    • setAppsURL

      public final void setAppsURL(String appsURL)
    • getApplication

      public final String getApplication()
      Returns:
      The mDNS service name. Usually "googlecast".
      See Also:
    • setApplication

      public final void setApplication(String application)
    • getTitle

      public final String getTitle()
      Returns:
      The name of the device as entered by the person who installed it. Usually something like "Living Room Chromecast".
    • getAppTitle

      public final String 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

      public final String getModel()
      Returns:
      The model of the device. Usually "Chromecast" or, if Chromecast is built into your TV, the model of your TV.
    • connect

      public final void connect() throws IOException, GeneralSecurityException
      Throws:
      IOException
      GeneralSecurityException
    • disconnect

      public final void disconnect() throws IOException
      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. calling connect() or disconnect() 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 autoReconnect setting, 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

      public final Status getStatus() throws IOException
      Returns:
      current chromecast status - volume, running applications, etc.
      Throws:
      IOException
    • getRunningApp

      public final Application getRunningApp() throws IOException
      Returns:
      descriptor of currently running application
      Throws:
      IOException
    • isAppAvailable

      public final boolean isAppAvailable(String appId) throws IOException
      Parameters:
      appId - application identifier
      Returns:
      true if application is available to this chromecast device, false otherwise
      Throws:
      IOException
    • isAppRunning

      public final boolean isAppRunning(String appId) throws IOException
      Parameters:
      appId - application identifier
      Returns:
      true if application with specified identifier is running now
      Throws:
      IOException
    • launchApp

      public final Application launchApp(String appId) throws IOException
      Parameters:
      appId - application identifier
      Returns:
      application descriptor if app successfully launched, null otherwise
      Throws:
      IOException
    • stopApp

      public final void stopApp() throws IOException

      Stops currently running application

      If no application is running at the moment then exception is thrown.

      Throws:
      IOException
    • stopSession

      public final void stopSession(String sessionId) throws IOException

      Stops the session with the given identifier.

      Parameters:
      sessionId - session identifier
      Throws:
      IOException
    • setVolume

      public final void setVolume(float level) throws IOException
      Parameters:
      level - volume level from 0 to 1 to set
      Throws:
      IOException
    • setVolumeByIncrement

      public final void setVolumeByIncrement(float level) throws IOException
      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

      public final void setMuted(boolean muted) throws IOException
      Parameters:
      muted - is to mute or not
      Throws:
      IOException
    • getMediaStatus

      public final MediaStatus getMediaStatus() throws IOException

      If no application is running at the moment then exception is thrown.

      Returns:
      current media status, state, time, playback rate, etc.
      Throws:
      IOException
    • play

      public final void play() throws IOException

      Resume paused media playback

      If no application is running at the moment then exception is thrown.

      Throws:
      IOException
    • pause

      public final void pause() throws IOException

      Pause current playback

      If no application is running at the moment then exception is thrown.

      Throws:
      IOException
    • seek

      public final void seek(double time) throws IOException

      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

      public final MediaStatus load(String url) throws IOException

      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 displayed
      thumb - url of video thumbnail to be displayed, relative to media url
      url - media url
      contentType - MIME content type
      Returns:
      The new media status that resulted from loading the media.
      Throws:
      IOException
    • load

      public final MediaStatus load(Media media) throws IOException

      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 namespace
      request - request object
      responseClass - class of the response for proper deserialization
      Returns:
      deserialized response
      Throws:
      IOException
    • send

      public final void send(String namespace, Request request) throws IOException

      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 namespace
      request - request object
      Throws:
      IOException
    • registerListener

      public final void registerListener(ChromeCastSpontaneousEventListener listener)
    • unregisterListener

      public final void unregisterListener(ChromeCastSpontaneousEventListener listener)
    • registerConnectionListener

      public final void registerConnectionListener(ChromeCastConnectionEventListener listener)
    • unregisterConnectionListener

      public final void unregisterConnectionListener(ChromeCastConnectionEventListener listener)
    • toString

      public final String toString()
      Overrides:
      toString in class Object