/Ti.Chromecast

Titanium module for using of chromecast protocol

Primary LanguageJavaScriptOtherNOASSERTION

Ti.Chromecast

This is a Titanium module for controling Google's chromecast and WIP. Thanks for help to Андрей, Stefan and Manumaticx.

For iOS version please look here: https://github.com/ajwhite/titanium-chromecast.

Attention!!

The used google library (google-play-service.cast and others) uses more then one aar. In current version of Titanium SDK every module can only contains one res folder. Therefore the build process of app needs a patch. You find it in android/ti-cli-5 (or ti-cli-6) folder. This patch uses the aars in aar folder of module to create R.classes.

Constants

Device types

  • DEVICE_TYPE_BLUETOOTH
  • DEVICE_TYPE_SPEAKER
  • DEVICE_TYPE_TV
  • DEVICE_TYPE_UNKNOWN
  • DEVICE_TYPE_BLUETOOTH

Connection state

  • CONNECTION_STATE_DISCONNECTED
  • CONNECTION_STATE_CONNECTING
  • CONNECTION_STATE_CONNECTED

Category

  • CATEGORY_LIVE_AUDIO
  • CATEGORY_LIVE_VIDEO
  • CATEGORY_REMOTE_PLAYBACK

Usage:

Initialisation

First you have to put this line into app.js:

require('ti.chromecast');

Browsing for chromecasts:

// reference the module
var Chromecast = require('ti.chromecast');

Chromecast.start({
    changed : function(routes) {
		routes.forEach(route) {
			console.log(route.getName())
		}
 	},
 	categories : [Cast.CATEGORY_LIVE_AUDIO, Cast.CATEGORY_REMOTE_PLAYBACK]
});
// you can ask:
var routes = MediaRouter.getRoutes();
routes && routes.forEach(function(){
	// call some methods, explained below
});

// or listen to changes
MediaRouter.addEventListener("onchanged",fucntion(e){
    e.routes.forEach(function(route){
       // call some methods, explained below
    });
});

You can use callback or event listener. With stop you can stop the listener:

MediaRouter.stop();    // after closing windo or hiding of dialog

With the result (array of routes) you can build a selector for device. I.e. a Ti.UI.OptionDialog().

Methods of route

A route has these methods:

  • getName();
  • getDescription();
  • isSelected();
  • isEnabled();
  • getDeviceType();
  • getConnectionState()
  • select(); // next chapter

Selecting of route (device)

Route.select();
Route.addEventListener("selected",function(){
});

Sending control request

  • playRemotePlayback()
  • enqueueRemotePlayback()
  • startLiveAudio()
  • startLiveVideo()