All Projects → vitalidze → Chromecast Java Api V2

vitalidze / Chromecast Java Api V2

Licence: apache-2.0
Java implementation of ChromeCast V2 protocol client

Programming Languages

java
68154 projects - #9 most used programming language

Projects that are alternatives of or similar to Chromecast Java Api V2

Addon Aircast
AirCast - Home Assistant Community Add-ons
Stars: ✭ 100 (-54.75%)
Mutual labels:  chromecast
Cloudstream 2
CloudStream 2 is an android streaming app for movies, tv-shows and anime
Stars: ✭ 120 (-45.7%)
Mutual labels:  chromecast
Rapidbay
Self-hosted torrent video streaming service compatible with Chromecast and AppleTV deployable in the cloud
Stars: ✭ 163 (-26.24%)
Mutual labels:  chromecast
Anexplorer
📁 Another Android Explorer ( File Manager ) is an All-in-One Open source file manager. AnExplorer File Manager (File Explorer) is designed for all android devices including Phones, Phablets, Tablets, Chromecast, Wear OS, Android TV and Chromebooks. It's a fully designed with Material guidelines by Google.
Stars: ✭ 1,505 (+581%)
Mutual labels:  chromecast
Mmusiccast
Chromecast emulator that works on any platform. Stream videos from youtube to raspberry pi or any computer with the chromecast protocol.
Stars: ✭ 113 (-48.87%)
Mutual labels:  chromecast
Mkchromecast
Cast macOS and Linux Audio/Video to your Google Cast and Sonos Devices
Stars: ✭ 1,837 (+731.22%)
Mutual labels:  chromecast
Fx cast
Implementation of the Google Cast Chrome Sender SDK within Firefox
Stars: ✭ 1,319 (+496.83%)
Mutual labels:  chromecast
Chromecast Desktop Audio Streamer
Stream the sound of your desktop to your Chromecast Audio device
Stars: ✭ 196 (-11.31%)
Mutual labels:  chromecast
Vinyl Cast
Listen to vinyl records wirelessly throughout your home using an Android device.
Stars: ✭ 119 (-46.15%)
Mutual labels:  chromecast
Chromecast Device Emulator
Testing your chromecast receiver app, without a real-device needed.
Stars: ✭ 155 (-29.86%)
Mutual labels:  chromecast
Multicast Relay
Relay multicast and broadcast packets between interfaces.
Stars: ✭ 111 (-49.77%)
Mutual labels:  chromecast
Castjs
📺 Chromecast Sender Library for the Browser
Stars: ✭ 112 (-49.32%)
Mutual labels:  chromecast
Streaming
r/freemediaheckyeah
Stars: ✭ 147 (-33.48%)
Mutual labels:  chromecast
Alexacast
Chromecast support for Amazon Alexa
Stars: ✭ 109 (-50.68%)
Mutual labels:  chromecast
Airconnect
Use AirPlay to stream to UPnP/Sonos & Chromecast devices
Stars: ✭ 2,349 (+962.9%)
Mutual labels:  chromecast
Chromecastcore
An open source implementation of the Google Cast SDK for macOS
Stars: ✭ 95 (-57.01%)
Mutual labels:  chromecast
Killcast
Manipulate Chromecast Devices in your Network
Stars: ✭ 133 (-39.82%)
Mutual labels:  chromecast
Gnome Shell Extension Cast To Tv
Cast files to Chromecast, web browser or media player app over local network.
Stars: ✭ 200 (-9.5%)
Mutual labels:  chromecast
Pychromecast
Library for Python 3 to communicate with the Google Chromecast.
Stars: ✭ 2,262 (+923.53%)
Mutual labels:  chromecast
Chromecastize
Bash script to convert video files into Google Chromecast supported format.
Stars: ✭ 151 (-31.67%)
Mutual labels:  chromecast

ChromeCast Java API v2 Build Status

At the moment I have started implementing this library, there was a java implementation of V1 Google ChromeCast protocol, which seems to be deprecated and does not work for newly created applications. The new V2 protocol is implemented by tools that come with Cast SDK, which is available for Android, iOS and Chrome Extension as javascript. Also there is a third party implementation of V2 in Node.js. This project is a third party implementation of Google ChromeCast V2 protocol in java.

Install

Library is available in maven central. Put lines below into you project's pom.xml file:

<dependencies>
...
  <dependency>
    <groupId>su.litvak.chromecast</groupId>
    <artifactId>api-v2</artifactId>
    <version>0.11.3</version>
  </dependency>
...
</dependencies>

Or to build.gradle (mavenCentral() repository should be included in appropriate block):

dependencies {
// ...
    compile 'su.litvak.chromecast:api-v2:0.11.3'
// ...
}

Build

To build library from sources:

  1. Clone github repo

    $ git clone https://github.com/vitalidze/chromecast-java-api-v2.git

  2. Change to the cloned repo folder and run mvn install

    $ cd chromecast-java-api-v2 $ mvn install

  3. Then it could be included into project's pom.xml from local repository:

<dependencies>
...
  <dependency>
    <groupId>su.litvak.chromecast</groupId>
    <artifactId>api-v2</artifactId>
    <version>0.11.4-SNAPSHOT</version>
  </dependency>
...
</dependencies>

Usage

This is still a work in progress. The API is not stable, the quality is pretty low and there are a lot of bugs.

To use the library, you first need to discover what Chromecast devices are available on the network.

ChromeCasts.startDiscovery();

Then wait until some device discovered and it will be available in list. Then device should be connected. After that one can invoke several available operations, like check device status, application availability and launch application:

ChromeCast chromecast = ChromeCasts.get().get(0);
// Connect (optional) 
// Needed only when 'autoReconnect' is 'false'. 
// Usually not needed and connection will be established automatically.
// chromecast.connect();
// Get device status
Status status = chromecast.getStatus();
// Run application if it's not already running
if (chromecast.isAppAvailable("APP_ID") && !status.isAppRunning("APP_ID")) {
  Application app = chromecast.launchApp("APP_ID");
}

To start playing media in currently running media receiver:

// play media URL directly
chromecast.load("http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4");
// play media URL with additional parameters, such as media title and thumbnail image
chromecast.load("Big Buck Bunny",           // Media title
                "images/BigBuckBunny.jpg",  // URL to thumbnail based on media URL
                "http://commondatastorage.googleapis.com/gtv-videos-bucket/sample/BigBuckBunny.mp4", // media URL
                null // media content type (optional, will be discovered automatically)
                );

Then playback may be controlled with following methods:

// pause playback
chromecast.pause();
// continue playback
chromecast.play();
// rewind (move to specified position (in seconds)
chromecast.seek(120);
// update volume
chromecast.setVolume(0.5f);
// mute
chromecast.setMuted(true);
// unmute (will set up volume to value before muting)
chromecast.setMuted(false);

Also there are utility methods to get current chromecast status (running app, etc.) and currently played media status:

Status status = chromecast.getStatus();
MediaStatus mediaStatus = chromecast.getMediaStatus();

Current running application may be stopped by calling stopApp() method without arguments:

// Stop currently running application
chromecast.stopApp();

Don't forget to close connection to ChromeCast device by calling disconnect():

// Disconnect from device
chromecast.disconnect();

Finally, stop device discovery:

ChromeCasts.stopDiscovery();

Alternatively, ChromeCast device object may be created without discovery if address of chromecast device is known:

ChromeCast chromecast = new ChromeCast("192.168.10.36");

Since v.0.9.0 there is a possibility to send custom requests using send() methods. It is required to implement at least Request interface for an objects being sent to the running application. If some response is expected then Response interface must be implemented. For example to send request to the DashCast application:

Request interface implementation

public class DashCastRequest implements Request {
    @JsonProperty
    final String url;
    @JsonProperty
    final boolean force;
    @JsonProperty
    final boolean reload;
    @JsonProperty("reload_time")
    final int reloadTime;

    private Long requestId;

    public DashCastRequest(String url,
                           boolean force,
                           boolean reload,
                           int reloadTime) {
        this.url = url;
        this.force = force;
        this.reload = reload;
        this.reloadTime = reloadTime;
    }

    @Override
    public Long getRequestId() {
        return requestId;
    }

    @Override
    public void setRequestId(Long requestId) {
        this.requestId = requestId;
    }
}

Sending request

chromecast.send("urn:x-cast:es.offd.dashcast", new DashCastRequest("http://yandex.ru", true, false, 0));

This is it for now. It covers all my needs, but if someone is interested in more methods, I am open to make improvements.

Useful links

Projects using library

  • UniversalMediaServer - powerful server application that serves media to various types of receivers (including ChromeCast)
  • SwingChromecast - A graphical user interface to interact with your chromecasts. (Written in Java 8 with swing)

License

(Apache v2.0 license)

Copyright (c) 2014 Vitaly Litvak [email protected]

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].