Blog

A sender application or Google Cast application refers to an app running on a mobile device (the sender device).

Setup

Download the latest version of the Android SDK using the Android SDK Manager.

Install the Android Support Libraries through the Android SDK Manager. The support libraries need to be revision 19.0.1 or later.

Install the Google Play services SDK through the Android SDK Manager. The Google Play services SDK needs to be revision 4.2 or later.

Add Libraries

The following libraries are required :

android-support-v7-appcompat : path to this library is <SDK install location>/extras/android/support/v7/appcompat

android-support-v7-mediarouter : path to this library is <SDK install location>/extras/android/support/v7/mediarouter

google-play-services_lib : path to this library is <SDK install location>/extras/google/google_play_services/libproject/google-play-services_lib

Note

Import these libraries as library projects for your IDE instead of including their JAR files

Android-support-v7-mediarouter has a dependency on android-support-v7-appcompat, so add it by selecting the android-support-v7-mediarouter project Properties, then select Android, and in the Libraries list, add android-support-v7-appcompat.

Ensure the build target for each of the imported libraries is same : select the library project Properties and then select Android. Select a different Project Build Target, select "Apply", then re-select the desired target (> API 17) and hit "Apply" again.

Development

Android manifest

Add following configuration in AndroidManifest.xml file to use the Cast SDK:

Internet permission

uses-sdk

The minimum Android SDK version that the Cast SDK supports is 9 (GingerBread).

meta-data

android:theme

The applicationís theme needs to be correctly set based on the minimum Android SDK version.

...

Adding the Cast Button

The MediaRouter framework provides a Cast button and a list selection dialog for selecting a route. There are three ways to support a Cast button:

Using the MediaRouter ActionBar provider: android.support.v7.app.MediaRouteActionProvider

Using the MediaRouter Cast button: android.support.v7.app.MediaRouteButton

Developing a custom UI with the MediaRouter APIís and MediaRouter.Callback

This blog describes the use of the MediaRouteActionProvider to add the Cast button to the ActionBar.This action bar button handles all of the state logic needed for hiding or displaying the casting button, as well as coloring it when the app has connected to a casting device.Add the media routing button to our menu.xml as follows :

Add some values to strings.xml, such as the video URL, receiver application ID and general UI strings.You'll need to replace app_id

with your application ID, and video_url with a video that you would want to play.

The UI for this activity consists of a single button that will start a video if the app is connected to a casting device, or can pause/resume a video once it has been started, and the media router button in the action bar.The action bar button will display only if you are connected with chromecast device on the same wifi network.