Uncaught (in promise) invalid_parameter – Debugging Google Cast Error

I’m tinkering with the Google Cast API at home to play some music that I have. I’m using the messaging system to send commands to do various things. I was getting the following message and my error callback wasn’t being called:

Uncaught (in promise) invalid_parameter

This was a slightly puzzling problem, and I’ve identified the cause (at least in my case).

In my receiver, I had the following code:

window.mediaElement = document.getElementById('media');
 window.mediaManager = new cast.receiver.MediaManager(window.mediaElement);
 window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
 window.castReceiverManager.start();

var customMessageBus = castReceiverManager.getCastMessageBus('urn:x-cast:org.jaredstevens.mediabase');
 customMessageBus.onMessage = function(event) {
 document.getElementById('message').innerHTML = "Got message: "+event;
 }

What’s causing my problem is I’m calling window.castReceiverManager.start(); before my message bus has been setup. Making the following modification corrects the issue:

window.mediaElement = document.getElementById('media');
 window.mediaManager = new cast.receiver.MediaManager(window.mediaElement);
 window.castReceiverManager = cast.receiver.CastReceiverManager.getInstance();
 

var customMessageBus = castReceiverManager.getCastMessageBus('urn:x-cast:org.jaredstevens.mediabase');
 customMessageBus.onMessage = function(event) {
 document.getElementById('message').innerHTML = "Got message: "+event;
 }

window.castReceiverManager.start();

I hope this helps!

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s