Reusable Polymer element to simplify cast integration
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Failed to load latest commit information.

Copyright 2014 Google Inc. All Rights Reserved.

Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.


The cast-manager Polymer element is the controller for the other Cast Polymer elements. It exposes a number of properties which define the current state, it also handles events and routes them to the subscribed elements.

The goal of cast-manager is to provide a simpler wrapper for the Cast SDK and local media playback. It handles all of Cast integration and state management for you and simplifies interaction down to a few calls. Instead of integration taking weeks it can take a few minutes.

Here is a demo of cast-manager being used along with the source.

cast-manager can be used with any other Polymer element. Several are provided to use out of the box:

  • cast-video - Handles displaying and controlling video
  • cast-controller-bar - Controller for the Chromecast when standard video controls aren't on screen. Also displays the queue UI.
  • cast-dialog - Notifies users that the page is cast enabled. Also handles the upcoming video notification and count down.

You can find a codelab for using all of the elements together here.

You can find an overview of how to create a Polymer element here.


This section covers including the cast-manager element in your project



In your project directory install cast-manager using bower. You may need to first bower init.

bower install --save googlecast/cast-manager-polymer


This section covers adding the cast-manager element to your page

Include dependencies

As part of head, you want to include Polymer JS and cast-manager.

<script src="bower_components/webcomponentsjs/webcomponents-lite.min.js"></script>

<link rel="import" href="bower_components/cast-manager-polymer/cast-manager.html">

Define elements

If you're defining this outside of a Polymer element, you'll need to wrap cast-manager in an auto binding template in the <body> to leverage property binding.

<template id="t" is="dom-bind">

Add the cast-manager element as a child of the auto binding template

<template id="t" is="dom-bind">
  <cast-manager ...>

Get a reference to cast-manager

If you've used an auto binding template you'll need to wait until the cast-manager element has been added to the dom. The auto binding template fires a dom-change event that you can listen for.

var t = document.querySelector('#t');
t.addEventListener('dom-change', function () {
  castManager = document.querySelector('cast-manager');

Define app-id

The app-id is an attribute of cast-manager. You need to specify the app-id of your receiver app. A demo receiver app-id is 4F8B3483. To create your own appId refer to the Cast Registration documentation.

Define bindable attributes

cast-manager provides a number of properties to bind to. You can choose to expose the properties your app needs. The sample exposes the following:

<cast-manager app-id="4F8B3483"

Definitions for each of the properties can be found in cast-manager.html.

Loading video

cast-manager uses cast.MediaItem to represent media locally. Details on the object can be found in media-item.html. It manages conversion between the local cast.MediaItem and the cast .QueueItem using helper methods _castMediaToLocalMedia and _localMediaToCastMedia.
cast-manager provides a few ways to load media and provides a single call for both local playback and cast playback.

Single Video

There are two ways to load a single video. It's recommended to use the cast-video element for playback since it simplifies integration to a few steps.

Method One: setLocalMedia

Get a reference to the cast-manager

var castManager = document.querySelector('cast-manager');

Use the setLocalMedia and pass in a cast.MediaItem as the parameter.

Method Two: cast-video src

When using cast-video you can load an element when defining the attributes of cast-video.

<cast-video id="video"


Loading a queue is similar to loading a single video method one. You'll need to get a reference to cast-video and call addItemsToQueue with an array of cast.MediaItems.


Playback control

Most playback controls are handled by the elements. They fire events up to cast-manager which then route the events to subscribed elements.

If you want to handle playback control externally, you first need to get a reference to cast-manager. Then call one of the playback control methods such as play, pause, seek or setVolume.

var castManager = document.querySelector('cast-manager');;
castManager.pause();; // Time in seconds to seek to from the beginning
castManager.volume(1); // Volume from 0 - 1

Browser Support

Cast support

  • Chrome

The elements will work in browsers that support Polymer with out cast functionality.

  • Firefox
  • IE 10+
  • Safari 8+


Your use of this sample is subject to, and by using or downloading the sample files you agree to comply with, the Google APIs Terms of Service and the Google Cast SDK Additional Developer Terms of Service.