Appearance
Chromecast API v2 Resources
When you want to cast content from The Radio Hub to a Chromecast connected to a tv, you can use the The Radio Hub Chromecast Receiver. You can connect to our receiver and send commands to play a stream or start our crossfading youtube player.
Create a Sender Application
Connect to a Chromecast and load the The Radio Hub Application before doing anything else. Use the libraries provided by Google to do that. See https://developers.google.com/cast/docs/sender_apps for tips and requirements to get you started. Examples on this page use the javascript syntax, but the documentation from Google mentions other languages as well.
Parameters
| Parameter | Required | Description |
|---|---|---|
| application id | Required | The id of the Custom Receiver Application from The Radio Hub is 0FBEED1A |
Successfull connection
Once you are connected to a Chromecast, a The Radio Hub loading screen will show. Now you can send commands.
Stream & Nowplaying info
Plays the radio stations' audio while showing the now playing information on screen.
Steps
- Create a mediainfo object, telling the Chromecast player to play a stream.
js
const media = new chrome.cast.media.MediaInfo('playStream', 'text/plain');Advanced mode: set your own stream url
- Do not send
playStreamas plain text, but create a mediainfo object with the stream url you want to play.
js
const media = new chrome.cast.media.MediaInfo('stream url', 'audio/mp3');- Create a Loadrequest object with the media in it:
js
const load = new chrome.cast.media.LoadRequest(media);- Add the station id in the custom data:
js
load.customData = {
stationId: 53 // Radio Haugaland
}- Send the request to the Chromecast
js
const currentSession = this.getCurrentSession();
currentSession.loadMedia(load).then(
() => { console.log('Load succeed'); },
(errorCode) => { console.log('Error code: ' + errorCode); });Videoplaylist
Shows a fullscreen videoplaylist, with radio station branding. This call allows you to play a list of youtube video's in a crossfading player.
Steps
- Create a mediainfo object with the stream url you want to play.
js
const media = new chrome.cast.media.MediaInfo('the youtube id of the first video', 'video/youtube');- Create a Loadrequest object with the media in it:
js
const load = new chrome.cast.media.LoadRequest(media);- Create a queue with all the videos you want to play (including the first track).
js
const queue = new chrome.cast.media.QueueData();
queue.items = tracks.map((track) => {
const mediainfo = new chrome.cast.media.MediaInfo(track.youtube_id, 'video/youtube');
mediainfo.metadata = new chrome.cast.media.GenericMediaMetadata();
mediainfo.metadata.title = track.title;
mediainfo.metadata.artist = track.artist;
return new chrome.cast.media.QueueItem(mediainfo);
});
load.queueData = queue;- Add the station id in the custom data:
js
load.customData = {
stationId: 53 // Radio Haugaland
}- Send the request to the Chromecast
js
const currentSession = this.getCurrentSession();
currentSession.loadMedia(load).then(
() => { console.log('Load succeed'); },
(errorCode) => { console.log('Error code: ' + errorCode); });Userlikes videoplaylist
Shows a fullscreen videoplaylist with songs the user liked, with radio station branding. The playlist will be mixed with songs from the radio station.
- Create a mediainfo object
js
const media = new chrome.cast.media.MediaInfo('playUserLikes', 'text/plain');- Create a Loadrequest object with the media in it:
js
const load = new chrome.cast.media.LoadRequest(media);- Add the station id and user info in the custom data:
js
load.customData = {
stationId: 53, // Radio Haugaland
action: 'playUserLikes',
type: 'user',
typeId: 9 // user-id
}- Send the request to the Chromecast
js
const currentSession = this.getCurrentSession();
currentSession.loadMedia(load).then(
() => { console.log('Load succeed'); },
(errorCode) => { console.log('Error code: ' + errorCode); });