Chromecast binding - Unable to load media

  • Platform information:
    • Hardware: Raspberry pi4
    • OS: Openhabian
    • Java Runtime Environment: 17.0.7
    • openHAB version: 4.0.3

I’m having an issue with the Chromecast binding. I wanted to play a URL from youtube music playlist, like: YouTube Music from within a rule. I tried two ways of loading the url but both gave me the unable to load media error. First I tried to load the Channel: “chromecast:audiogroup:Audio:playuri” with an Item (i’m running fully text based) and I tried the Actions method:

castActions.playURL("https://music.youtube.com/watch?v=UCvX656hxHk&list=OLAK5uy_mUT61aE7EqrjT5tFRrbI23qnwSuZN50s8")

I tested the Say command with the chromecast audio, and that just worked. So I searched a bit on the forum and found a couple of topic where the use of Services.cfg could work. Not sure how and why but I tested it. I created the services.cfg file in the Services directory and added the code:

binding.chromecast:callbackUrl=http://192.168.0.227:8080 
&& also:
binding.chromecast:callbackUrl=http://192.168.0.227:32000

But that didn’t help and still got the error.

[.openhab.binding.chromecast.internal.ChromecastCommander] - Unable to load media: http://192.168.0.227:8080/audio/ff6c2252-b1cf-431d-afb0-f2c667547efb

With debug:

2023-11-07 22:36:30.725 [DEBUG] [nhab.binding.chromecast.internal.ChromecastEventReceiver] - Received an 'UNKNOWN' event (class=class com.fasterxml.jackson.databind.JsonNode)
2023-11-07 22:36:31.924 [DEBUG] [.openhab.binding.chromecast.internal.ChromecastCommander] - Application launched: CC1AD845
2023-11-07 22:36:32.284 [DEBUG] [nhab.binding.chromecast.internal.ChromecastStatusUpdater] - MEDIA_STATUS MediaStatus{activeTrackIds: <null>, mediaSessionId: 1, playbackRate: 1, playerState: IDLE, currentItemId: 1, currentTime: 0.000000, customData: <null>, loadingItemId: null, items: <null>, preloadedItemId: null, supportedMediaCommands: 12303, volume: Volume{level: 1.0, muted: false, increment: 0.05, stepInterval: 0.05000000074505806, controlType: null}, media: Media{url: http://192.168.0.227:32000/audio/6b17824c-3162-44b4-b066-4969359a4e6b, contentType: audio/wav, duration: null}, repeatMode: REPEAT_OFF, idleReason: null}
2023-11-07 22:36:32.349 [WARN ] [.openhab.binding.chromecast.internal.ChromecastCommander] - Unable to load media: http://192.168.0.227:32000/audio/6b17824c-3162-44b4-b066-4969359a4e6b
2023-11-07 22:36:32.386 [DEBUG] [nhab.binding.chromecast.internal.ChromecastStatusUpdater] - MEDIA_STATUS MediaStatus{activeTrackIds: <null>, mediaSessionId: 1, playbackRate: 1, playerState: IDLE, currentItemId: 1, currentTime: 0.000000, customData: <null>, loadingItemId: null, items: <null>, preloadedItemId: null, supportedMediaCommands: 12303, volume: Volume{level: 1.0, muted: false, increment: 0.05, stepInterval: 0.05000000074505806, controlType: null}, media: null, repeatMode: null, idleReason: ERROR}
==> /var/log/openhab/events.log <==
2023-11-07 22:36:32.402 [INFO ] [openhab.event.ItemStateChangedEvent      ] - Item 'GoogleTitle' changed from Notification to UNDEF
==> /var/log/openhab/openhab.log <==
2023-11-07 22:36:33.424 [DEBUG] [mecast.internal.discovery.ChromecastDiscoveryParticipant] - Chromecast Type: Nest Audio
2023-11-07 22:36:33.425 [DEBUG] [mecast.internal.discovery.ChromecastDiscoveryParticipant] - Chromecast Found: 192.168.0.227 8009
2023-11-07 22:36:33.426 [DEBUG] [mecast.internal.discovery.ChromecastDiscoveryParticipant] - Chromecast Type: Nest Audio
2023-11-07 22:36:33.431 [DEBUG] [mecast.internal.discovery.ChromecastDiscoveryParticipant] - Chromecast Type: Google Cast Group
2023-11-07 22:36:33.432 [DEBUG] [mecast.internal.discovery.ChromecastDiscoveryParticipant] - Chromecast Found: 192.168.0.227 32000
2023-11-07 22:36:33.433 [DEBUG] [mecast.internal.discovery.ChromecastDiscoveryParticipant] - Chromecast Type: Google Cast Group
2023-11-07 22:36:33.437 [DEBUG] [mecast.internal.discovery.ChromecastDiscoveryParticipant] - Chromecast Type: Nest Audio
2023-11-07 22:36:33.438 [DEBUG] [mecast.internal.discovery.ChromecastDiscoveryParticipant] - Chromecast Found: 192.168.0.238 8009
2023-11-07 22:36:33.439 [DEBUG] [mecast.internal.discovery.ChromecastDiscoveryParticipant] - Chromecast Type: Nest Audio
2023-11-07 22:36:36.304 [DEBUG] [nhab.binding.chromecast.internal.ChromecastStatusUpdater] - MEDIA_STATUS null

So I removed the services file. But I noticed, the say command didn’t work anymore and also gave the log error. I added the services.cfg file again, empty and with another port. That didn’t do anything. I restarted Openhab, also without result. So I stopped the openhab service, cleaned cache and restarted. Again the same error when using anything regarding the chromecast. So I deleted the Chromecast Thing and added a new one. But it’s the same error with the new one.

I’m completely lost with this one. Not sure why the error persists. I’m hoping I could play a playlist from youtube music, that would open the door to NFC tags loading a playlist to my chromecast audio speakers. But most important, I want to be able to send TTS voice audio to my chromecast audio speakers.

Anyone a clue in the right direction where to search?

[edit] - The binding works when I play music, I see the song info and artist and i’m able to pause the music / change volume etc.

I checked the error in the log file and it looks like the [binding.chromecast:callbackUrl=] in services.cfg is the issue. When I change that, the error changes with it. I just changed it to : binding.chromecast:callbackUrl= and now the log is:

Unable to load media: /audio/a4c3d17c-1da3-4883-8190-2b02525d7cac

So without any host address. So it’s still using the services.cfg file, regardless I delete it or empty it.

I suspect the problem is the URL that needs to be sent to the Chromecast is different from the URL you go to in the browser.

The URL you are using above is to a web page. The Chromecast needs a URL that opens the actual media (i.e. the audio file/stream), not a web page. And it’s notoriously challenging to find that from YouTube.

I also think that’s the reason why loading a playlist doesn’t work. That’s unfortunate, but can live without it.

The real problem is that the binding just doesn’t work anymore and it looks like services.cfg is the culprit. Even when deleting the file, the binding want’s to use this callbackUrl, and it shouldn’t because that doesn’t work with my setup… I am trying everything now to get the binding to “speak” again, but it doesn’t work anymore, because it still using the callbackUrl i guess.

I’m removing and adding the binding at this moment and waiting for every rule file to load again… but it takes a long time…Raspberry pi 4… lol

Keep in mind that changes made to services.cfg get copied to $OH_USERDATA/config/org/openhab/services.config. Just deleting that file I don’t think will cause anything copied to the config file that is the one that’s really used to also be deleted. That URL is likely still in the config. You need to remove it from there too I suspect.

I did not know that, I checked the file [services.config] and it’s different from the services.cfg i deleted:

:org.apache.felix.configadmin.revision:=L"1"
_felix_.cm.newConfiguration=B"true"
service.pid="org.openhab.services"

I also deleted that file but it’s still using an callbackUrl i used as last test (I reverted the file afterwards):

Unable to load media: http://192.168.0.227:433/audio/3851c525-c223-4e7f-b066-babd4eebe908

It’s bedtime now, so i’m continuing tomorrow after work. I will again clean cache and restart openhab.

Well this is getting pretty weird. What I just tested:

  • removed all the things (connected to the chromecast binding)
  • removed the binding form openhab
  • stopped openhab
  • Cleaned the cache
  • restarted openhab
  • added the binding again
  • added a new audiogroup for my speakers

the log again shows the old information I tested yesterday evening:

Unable to load media: http://192.168.0.227:433/audio/75672fa3-75b1-4ed3-bf89-d16e9e42d66a

[edit] To be clear, this was a voice command

say(strToBeSaid, strVoiceType, "chromecast:audiogroup:6ffac48b-f2d5-4c4b-936a-424b6f866d82"))

So i’m lost, only thing I can think of right now, is completely reinstall openhab, but I won’t do that :slight_smile:

There must be somewhere still be information saved regarding to chromecast after deletion of the binding… but where :slight_smile:

Are you certain this information isn’t part of the Thing? If it is it would definitely be restored when the Thing is redescovered even after you reinstalled from scratch.

Also keep in mind you have two things going on here.

Originally you tried to make it play a URL that it simply cannot play. In attempting to fix that you made all sorts of changes which has broken the TTV.

That music URL is never going to play. So forget about that. We need to focus on getting the TTV working again.

What is this callbackURL? Based on the docs:

When a Chromecast is used as an audio sink, the Chromecast connects to openHAB to get the audio streams. The binding sends the Chromecast URLs for getting the audio streams based on the Primary Address (Network Settings configuration) and openHAB HTTP port. These URL defaults can be overridden with the Callback URL configuration parameter.

Configure a Callback URL when the Chromecast cannot connect using the Primary Address or Port, e.g. when:

  • proxying HTTP (port 80/443) using Apache/NGINX to openHAB (port 8080)
  • openHAB is running inside a Docker container that has its own IP Address

So this is how the binding tells the Chromecast to connect to openHAB to retrieve the media to play when you ask it to do TTV.

So first, if you are not using a reverse proxy or running in Docker and if you are running in Docker you’ve selected the Docker 172.x.x.x/16 under Settings → Network Settings → Primary Address instead of 192.168.0.1/24 you should not touch this setting at all.

You are running openHABian so neither of these apply. You should not be setting the callbackURL.

I know that in 4.1 M2 the following works: Navigate to Settings → Add-on Settings → Chromecast Settings and verify that the callback url field is blank.

It might be in 4.0 you need to navigate to Settings → Bindings → Chromecast → Blue Gear icon in the upper right. Verify that the callback url field is blank.

If it won’t let you change it or if you change it but it comes back that probably means it’s hard coded in a config file somewhere.

Verify that you’ve not set anything related to /etc/openhab/services/services.cfg. If that file doesn’t exist or if it doesn’t have anything about binding.chromecast we need to look in another file. Verify there isn’t a chromecast.cfg file.

Look in /var/lib/openhab/config/org/openhab/services.config. I’m really hoping that this file got recreated after you deleted it because this file is needed by a lot more than just the Chromecast binding. If it doesn’t have anything about binding.chromecast look to see if there is a chromecast.config file in that same folder. If there is, go ahead and delete that one.

If you’ve made any changes to any of these files, restart openHAB and navigate to the settings in MainUI and verify that the callbackURL is not set.

If it’s still using a wrong callback url, then do a recursive grep through /var/lib/openhab for 192.168.0.227 and see where it shows up.

Note that http://192.168.0.227:433 is indeed not valid. 443 is the https port, not http. And unless you’ve set up a reverse proxy, it should be 8080, not 443.

grep -R 192.168.0.227

Note it should show up in a number of places. You’ll need to look at each file to see if it’s related to chromecast in any way.

I think my way of testing and problem solving is a bit off in comparison to most people :slight_smile: . I already stopped trying to get the link to work yesterday, (it should be able to play, playlists, but not how I did it or it’s just not supported).

You are running openHABian so neither of these apply. You should not be setting the callbackURL.

At first I didn’t want to change the services.cfg file. I always read a lot in the docs and it specifically said it was for reverse proxy or docker, so I ignored that part at first. But couldn’t get the playlist link to work, so you start trying all kinds of things :smiley: . So I searched this forum and several people got it to work by adding the callback url in the services.cfg file, with docker, but also without (at least, I didn’t read they used reverse proxy or docker, but I think they did…). I checked those posts again and they where from a long while ago…so old openhab versions.

Look in /var/lib/openhab/config/org/openhab/services.config. I’m really hoping that this file got recreated after you deleted it because this file is needed by a lot more than just the Chromecast binding.

I reverted the file afterwards, as I posted yesterday, everything is fine. To be clear, I never delete such files, I always rename the file extension. :slight_smile:

Note that http://192.168.0.227:433 is indeed not valid. 443 is the https port, not http. And unless you’ve set up a reverse proxy, it should be 8080, not 443.

I changed this wrong on purpose, so it would stood out and I was sure, it was my last changed setting in services.cfg other then it got it from anywhere else. I was trying to find how and why the setting came back every time. I was doubting to change my post here, and make it neat to prevent misconceptions, but I didn’t, lol :slight_smile: .

It might be in 4.0 you need to navigate to Settings → Bindings → Chromecast → Blue Gear icon in the upper right. Verify that the callback url field is blank.

This is where the callback settings is saved! I never thought it would be there to find!! Thanks for this! But… I strait away removed it and if I save it, the old settings comes back… :rage:

I tried filling in just a [space], just the Ip of my audiogroup. The IP address with correct port (32000 in a audiogroup case / my case). But none of it works. I just want to delete it, but it wont. I think this is a bug in the binding and i’m going to report it, hopefully it can be fixed :smiley:

Note, the callback need to point to openHAB, not to a Chromecast device. This is the URL the Chromecast uses to pull the audio from openHAB. It won’t work if it’s pulling from itself.

If your OH isn’t running on port 32000, that’s almost certainly wrong.

Settings made on that form in MainUI will get saved to /var/lib/openhab/config/org/openhab/chromecast.confg. Stop OH and delete that file and restart. It should be gone at that point.

No, it’s either a bug in core or MainUI. But it’s going to be hard to pinpoint any problem because you’ve done a mix of file based and UI based configs. File based configs will always take precedence over UI made configs and because of the mixing it will be hard to prove if there really is a problem or if it’s simply keeping the file based config.

It’s always best to choose one approach and stick to it. I prefer UI based where possible.

1 Like

I misunderstood the docs! But as I read your comment, it made sense. I changed it to my openhab server address and now it works! Thanks man!

Now I understand why I can’t delete it. No callbackUrl just doesn’t make sense.

Yeah, I know. I try to stick with file based, simply because of the ease to be able to copy and paste all my config as text files (I know there are several other ways for backup). The chromecast binding is just added to the addons.cfg file and doesn’t need a configuration text based, so that’s the reason I couldn’t find the culprit.

Again, thanks for helping me figure this one out! :smiley: