Chromecast and Xojo

Has anybody tried to drive a Chromecast from a xojo web app?

I’ve had a look at the API before for this.

Thinking it has to be a Web App through Chrome. To make Xojo work with it, wondering if the WebSDK is what’s needed to make this happen(?)

Very interested to see what I can/can’t do with the ChromeCast…

[quote=87519:@Patrick Delaney]Very interested to see what I can/can’t do with the ChromeCast…

From Chrome browser, you can cast to the device. You might need an app from the Chome App Store. But that casting is basically screen casting. It’s not telling the Chromecast to run its own session.

From what I can see on the Chromecast site, it works by mirroring the content of Chrome. So a web app should work.

Sure, but casting any Chrome tab works and therefore Xojo WebApps cast.

But, if you can access the ChromeCast API from within a Xojo webapp doesn’t that open up a whole other world of possibilities?

Haven’t looked in depth though…

Chromecast API is java based (not to be confused with javascript). The sender app can be anything which can load Java, or uses special libraries to load Java (ie iOS). The only way a webapp would work is when loaded in a Chrome browser using chrome API to interact.

Chromecast is a weird beast because the worst it works for is receiving “casts” from other devices. The best way it works is not as obvious for most: By connecting itself and asking for the content to play.

I assume you don’t want casting but a proper chromecast implementation. This means you want the chromecast to essentially run what is called a receiver interface. With these you can have a remote application (a web application, a xojo application, etc.) that talks to chromecast and asks it to play stuff. While you’re doing this what the chromecast is showing (and also while the video is being played) is a styled interface that can either be based off one of Google’s own templates or be a custom receiver.

A custom receiver interface does not run on java. It runs under html and javascript. It uses Google’s Receiver API, which is javascript.

So, if you wanted to use chromecast with Xojo you’d have to develop your application and do the chromecast part separately. And have the chromecast receiver speak to your application through an API of your making.

More info:

Receiver Applications:
Styled Receiver (essentially a CSS file that re-uses the templates from Google adding customisation):
(the app needs to be registered first here: )
Custom Receiver (your own “app” running in Chromecast, html+javascript):

BIG CAVEAT: If you go the Custom Receiver way, you need to register with Google, host your app in an https server and go through the internet. The Styled Receiver may be more flexible in this respect and, thus, a more suitable option.

small caveat: Any route requires a registration to the Google Cast SDK web, which costs $5.

In the end, you’ll essentially need to develop two apps, as the cast one can be considered one unto itself (even if you run it within your xojo app).

Here’s a summarised checklist:

I know how chromecast works, I’ve implemented it a number of times…html/javascript version is not as “robust” as the javascript implementation…but if you want an html/javascript implementation…here’s a demo I threw together…paste the code in two html documents…fill in the spots marked namespace and ID…put them on a server and browse to them…(then run an applet version to see the difference in quality of Javascript vs. Java :slight_smile: ) I just tested the demos I’m pasting below…they work.


<html data-cast-api-enabled="true">
		<title>Chrome Sender</title>
		<div class="receiver-div">
			<h3>Choose A Receiver</h3>
			<ul class="receiver-list">
				<li>Looking for receivers...</li>
		<button class="kill" disabled>Kill the Connection</button>

	<script src=""></script>
	<script src=""></script>

		var cast_api,
			$killSwitch = $('.kill');

		window.addEventListener('message', function(event) {
			if (event.source === window && && === 'CastApi' && === 'Hello') {

		initializeApi = function() {
			if (!cast_api) {
				cast_api = new cast.Api();
				cast_api.addReceiverListener('*** YOUR APP ID HERE ***', onReceiverList);

		onReceiverList = function(list) {
			if (list.length > 0) {
				receiverList = list;
				receiverList.forEach(function(receiver) {
					$listItem = $('<li><a href="#" data-id="' + + '">' + + '</a></li>');
					$listItem.on('click', receiverClicked);

		receiverClicked = function(e) {

			var $target = $(,
				receiver = _.find(receiverList, function(receiver) {
					return === $'id');


		doLaunch = function(receiver) {
			if (!cv_activity) {
				var request = new cast.LaunchRequest('*** YOUR APP ID HERE ***', receiver);

				$killSwitch.prop('disabled', false);

				cast_api.launch(request, onLaunch);

		onLaunch = function(activity) {
			if (activity.status === 'running') {
				cv_activity = activity;
				cast_api.sendMessage(cv_activity.activityId, '*** YOUR NAMESPACE HERE ***', {type: 'HelloWorld'});

		$killSwitch.on('click', function() {
			cast_api.stopActivity(cv_activity.activityId, function(){
				cv_activity = null;
				$killSwitch.prop('disabled', true);


<body class="initial">
	<div class="messages">
		<h1>Waiting for Messages...</h1>

<script src=""></script>
<script src=""></script>
	$(function() {
		var receiver = new cast.receiver.Receiver('*** YOUR APP ID ****', ['*** YOUR NAMESPACE ***']),
			channelHandler = new cast.receiver.ChannelHandler('*** YOUR NAMESPACE ***'),
			$messages = $('.messages'),
			$body = $('body');
			receiver.createChannelFactory('*** YOUR NAMESPACE ***'));


		channelHandler.addEventListener(cast.receiver.Channel.EventType.MESSAGE, onMessage.bind(this));

		function onMessage(event) {


Wow, guys. Thanks. I did create a Chrome app (not using xojo) but am now going to jump in a little further.

Thanks for the quick response and good info to follow up on.

I had written a long reply, clarifying about the (now forbidden unless rooted) use of the java libraries in non-android (like Fling) and what constitutes a “chromecast application”, for the benefit of future readers that may be searching for this, but the forum suddenly reloaded the tab and signed me off and I lost it all. So I’ll just drop the subject and go grumble to a corner.

I read you made a Chrome app. I assume this means a web running in Chrome with the cast extension loaded. Is this correct? At the moment the only accepted ways to use chromecast are iOS (with the linked C libraries and the Obj-C headers), Android (in Java) and Chrome with the Chromecast extension loaded. I wish this wasn’t so and it could be used from Binary apps but it just isn’t so at the time.

Xojo web apps should replicate what a chrome app does, loading the JS and offering the

Really good information in this thread, shame you lost your posting Eduardo! Thanks

I know this is slightly different than chromecast but I’ve had great success implement it in a Xojo webapplication…it really “spices” up conferencing capabilities in place of standard old “boring” chat demos

This option is also available in place of chromecast for screen sharing webapps and requires no plugins or extensions. … just javascript and a web accessible device