Showing posts with label chromecast tutorial. Show all posts
Showing posts with label chromecast tutorial. Show all posts

Sunday, May 4, 2014

Chromecast Development Tutorial - Getting Started

This guide is being moved to: http://chromecasthub.com/developers/
Please visit the site for complete tutorials and more resources for Chromecast programming!

Note: This is part of a multi-part series on developing web applications that integrate Google's Chromecast SDK. I am working on making a complete resource for web development with the Chromecast, so consider this a pre-release version and please comment if you see any issues or have recommendations on how to improve the tutorial.
Part 1 - Introduction
Part 2 - Getting Started
Part 3 - Hello World
Part 4 - Your Own First App


2 Getting Started


The first and foremost place to begin is the official Google Chromecast Developer’s site (https://developers.google.com/cast/).


Screen Shot 2014-04-24 at 12.01.39 AM.png

Figure 2-1 - The Chromecast Developer’s Homepage
If you’re reading this guide, it’s very likely that you have been to this site and left frustrated, exactly as I did. While the Chromecast is an excellent device, its documentation is unfortunately lacking. In the next few pages, I will be walking through the various steps required to begin working on developing a web application integrated with Chromecast.

Development Environment

I’m sure you already have a favorite text editor or programming environment setup. But if not, this is the part where you will want to download something more than just Notepad. Here are a few recommendations:
  • Sublime Text: Free “Development Edition”, Mac, Windows, Linux  http://www.sublimetext.com/
  • Komodo Edit: Free, Mac, Windows, Linux http://www.activestate.com/komodo-edit/downloads

There are thousands of editors, but you’ll only need one with HTML and JavaScript support (unless you plan to make a more functional website with Python, PHP, Ruby, etc.). Once you have installed your editor, you can begin writing code.

Server Environment

Personally, I develop locally on my machine before deploying to a virtual server hosted through a provider such as Amazon, DigitalOcean, Linode, or one of many others. When developing for the Chromecast, you will need to have a web server reachable via the Internet. This is because the Chromecast communicates with server directly rather than over the local WiFi connection. For example, when you cast a YouTube video, Google is receiving the instructions for casting, pausing, playing, etc. via YouTube.com

If you want your own dedicated IP address and server, the quickest and simplest method of getting a server online is through DigitalOcean (http://digitalocean.com). Their simplest plans cost only $5 at the time of publishing and have enough resources to host basic websites. Alternatively, you can use GitHub Pages (https://pages.github.com) for hosting of HTML, CSS, JavaScript, and media files. The prior link explains how to setup GitHub pages, so I will not walk through every step of that process. In this book, I will be using a standard Ubuntu Server with a dedicated public IP address.

If you choose to use a standalone server, ensure that Apache or some other web server alternative is setup (such as nginx). I will not be walking through this process, as setting up Apache is one of the most popular how-to guides on the Internet.

Additionally, you can host everything needed for your website on Google Drive (as long as it is a simple HTML application and doesn't use PHP, Node.JS, or another sever-side code base). Here is a video explaining how to host website on Google Drive (the easiest method):



Configuring the Chromecast

By default, the Chromecast is not setup for development. To enable development, you have to change a setting within the Chromecast Desktop App. You used this app when you first setup the Chromecast, but if you’ve deleted it since, you can redownload it at: https://cast.google.com/chromecast/setup/

Once you’ve installed the Chromecast application and ensured your device is online, click on the “Settings” button within the app.

Screen Shot 2014-04-24 at 12.26.14 AM.png
Figure 2-2 - Desktop Chromecast App

At the bottom of the settings page, check the box labeled “Send this Chromecast’s serial number to Google when checking for updates” and then reboot the Chromecast.

Screen Shot 2014-04-24 at 12.27.54 AM.png
Figure 2-3 - Chromecast Development Settings
Once the Chromecast is configured, ensure that you have the Chrome Chromecast Extension installed. It should appear at the top right of your browser, and clicking it should enable casting of the current tab or media if it is a supported page such as YouTube.

Developer Tools

Once you have enabled the checkboxes above and rebooted, you will have access to the developer tools of the Chromecast device. These tools look very similar to the standard Chrome developer tools and will become helpful later when developing receiver applications, so you may wish to check that you can access them now and familiarize yourself with them. They are located on port 9222 of the Chromecast. Find the Chromecast’s IP address via the application used previously (under “Settings”) and then access the tools via the browser at http://<ip-address>:9222.

You are now ready to begin Chromecast development! There are a few more “Setup” steps that I will discuss later, but they are not required to begin. In the next section, we will walk through downloading and running a demo app provided by Google so that you can understand how the Chromecast SDK is integrated into a website.

Chromecast Development Tutorial - Introduction

This guide is being moved to: http://chromecasthub.com/developers/
Please visit the site for complete tutorials and more resources for Chromecast programming!

Note: This is part of a multi-part series on developing web applications that integrate Google's Chromecast SDK. I am working on making a complete resource for web development with the Chromecast, so consider this a pre-release version and please comment if you see any issues or have recommendations on how to improve the tutorial.
Part 1 - Introduction
Part 2 - Getting Started
Part 3 - Hello World
Part 4 - Your Own First App

1 Introduction


On July 24th, 2013, Google released a small, thumb-drive sized HDMI device that quickly leapt to the top-seller charts on Amazon and many other shopping sites. The device, a $35 piece of hardware, was designed to bring the world of online streaming media to the television. The Chromecast solved the issue of using an HDMI cable from a laptop connected to a television simply to watch YouTube and other videos.
At first, the device was relatively limited, only supporting playback via Netflix as well as various Google properties such as YouTube and Google Play Music. Support for “casting” a tab through Chrome, as well as the entire desktop through a plugin, was added, but many users reported poor performance. This stemmed from the fact that, when a supported site (such as YouTube) was cast, the Chromecast played the file directly; yet when the tab itself was cast, the user’s computer acted as a web server, streaming the content to the device.

Despite working natively with YouTube, Netflix, and a small handful of other sites, the Chromecast did not work easily with other sites with video. This often led to sluggish performance as users attempted to cast a Flash video playing on a website to the Chromecast via the “Cast Tab” feature. A number of Android apps were developed that attempted to fix casting issues, but none were supported by Google and they broke often as the underlying APIs changed.

After several months, Google finally released an officially supported API to allow developers to integrate casting into their websites directly. Now, users of the site could cast the content directly to the device, bypassing the “Cast Tab” requirements. Additionally, Android and iOS SDKs were released to allow developers the ability to integrate Chromecast support directly into their applications.

Google has released a web, Android, and iOS SDK to allow direct communication with the Chromecast. This guide focuses solely on web development for the Chromecast. I do not have enough Android or iOS development experience to make a practical guide for those platforms, but hopefully some of the techniques provided here can be used interchangeably.

This guide contains a wealth of code samples and demonstrations that will hopefully ease the development process for integrating Chromecast onto your website. However, I assume that you have some experience with web development and are fairly comfortable with HTML and JavaScript. I have written this book because the documentation provided by Google is very basic and sometimes woefully incomplete. This guide is structured so that you can read it from beginning to end or skip to an applicable section. I cannot guarantee that the samples and explanations provided within will be accurate forever, as Google frequently changes the structure and functionality of their APIs. Now that the disclaimers are out of the way, let’s begin programming for the Chromecast!