Media-source://media_source/<media_dir>/<path> not working ERR_UNKNOWN_URL_SCHEME

Something doesn’t seem quite right, maybe it’s my understanding of how media_source works.

The browser isn’t getting the mp3 file, it doesn’t know how to handle the uri scheme.

GET media-source://media_source/media/local/front_door_open.mp3 net::ERR_UNKNOWN_URL_SCHEME


service: media_player.play_media
data:
  media_content_type: music
  media_content_id: media-source://media_source/media/local/front_door_open.mp3
target:
  entity_id:
    - media_player.browser_joe_home_office_chrome

The media folder is setup, I can see files and folders in the Media Browser tab. I’ve tried various paths… I’ve watch the error logs, I’m still scratching my head.

Any help or tips or pointers?
Thanks.

Try

service: media_player.play_media
data:
  media_content_type: music
  media_content_id: media/local/front_door_open.mp3
target:
  entity_id:
    - media_player.browser_joe_home_office_chrome

“media_content_id: media/local/front_door_open.mp3”

The browser will fetch “http://homeassistant:8123/developer-tools/media/local/front_door_open.mp3” when I try that from the developer tools…

if I run it from a script the browser tries to fetch
http://homeassistant:8123/config/script/edit/media/local/front_door_open.mp3

These are not the mp3 file

Not sure then as to be honest I have only just noticed you are trying to play the file via a browser, I have never tried this.

I use the same function / automation to play a local mp3 file to a google hub and the example I gave regarding location works perfectly, maybe sending to browser is different in some way.

If I swap the media_content_id for a public URL such as this one

service: media_player.play_media
data:
  media_content_type: music
  media_content_id: https://www.soundjay.com/buttons/beep-01a.mp3
target:
  entity_id:
    - media_player.browser_joe_home_office_chrome

It plays just fine…

I can try it with google home hub… That’s not where I want to be playing my sounds, but I’ll still give it a shot.

Tried it… doesn’t work. When I swap it out of the public url “https://www.soundjay.com/buttons/beep-01a.mp3” I get the expected beep.

But wait, there’s more…

I did finally have some success with media-source://media_source

service: media_player.play_media
data:
  media_content_type: music
  media_content_id: media-source://media_source/local/1.mp3
target:
  entity_id:
    - media_player.office_display
    - media_player.game_room_speaker

This works, but only works on the google devices…

How are people serving up sounds to their fullykiosk browsers, android or fire tablets, or amazon echo’s?

I could serve up the sounds locally on an unsecured webserver… seems like there is a better way.

OH….i made a typo on my first suggestion, it was missing the initial “/“

Should have suggested the following:

service: media_player.play_media
data:
  media_content_type: music
  media_content_id: /media/local/front_door_open.mp3
target:
  entity_id:
    - media_player.browser_joe_home_office_chrome

Ok… learning a bit more.

  1. Files in /media the ones that show up with the Media Browser default settings are the ones setup to work the the “media-source://media_source/local” URL schema

  2. This URL schema is not working at all when I use it with a non-google-cast device. such as the media_player thats in the browser mod plugin https://github.com/thomasloven/hass-browser_mod

  3. The location you’re referring to with /media/local/… is not the same location as where the Media Browser / media_source is finding it’s media… the url you’re referencing is the local file system /config/www/

Once I figured that out I was able to move my files from /media to /config/www and get it working in the browser.

I’m still trying to figure out how the media_source integration is supposed to work. https://github.com/home-assistant/core/tree/dev/homeassistant/components/media_source
Why is this even needed? It’s just adding some confusion to the whole mess.

Yes the reason is that google will play the files locally, so my example /local is exactly that “local” and is definitely not available outside the local network and therefore is not referencing the www folder as this is available to anyone that has the link / address.

That also is the reason why when you reference a file in the www folder your browser will access it because it’s available too anyone with the address. However if you try to get your browser to access the /local folder I suspect it cant gain access.

home assistant default config puts media folder as /local unless changed in the config or not running a standard install / setup. So the only files I see in HA media browser are those files and folders in /media/local

Similarly the www folder as the name suggests is accessible from the outside world.

So you can play a local file on a local device by referencing location /local OR if you host a file in the www folder you can access / play that file from anywhere if you reference to the file in the www folder.

Hope that makes sense :wink:

This part still makes no sense to me…

Why would I use this URL schema? media-source://media_source/local

Why would this work on my google devices, but not the browser?

I guess I’m off to go read the media_source integration source code on github:
Media Source - Home Assistant (home-assistant.io)