I am using a DLNA speaker and have no problem playing internet radio stations and a bunch of files I have cifs mounted in the local/ (www) folder of homeassistant.
However I cannot get playlists to work, a simple test.m3u fails to work.
I can use VLC with the same http://. . ./test.m3u file and it works.
I have also tried a different speaker, used BubbleUPnp on my phone, same result.
Using media_content_type: “music”
Any ideas on why .m3u would fail? Also noticed if I use media_content_type: “playlist” I get this error (short version):
File "/srv/homeassistant/lib/python3.5/site-packages/async_upnp_client/profiles/dlna.py", line 720, in _construct_play_media_metadata raise UpnpError('Unknown DIDL-lite type')
async_upnp_client.client.UpnpError: Unknown DIDL-lite type
It’s currently mounted manually, can be made permanent of course.
HA is running on Hassbian (cifs tools installed by default). I SSH in and do the following command.
sudo mount -t cifs //10.XX.XX.XXXX/media/Music/Flac /home/homeassistant/.homeassistant/www/music -o user=xxx
You will promoted for a password, assuming you require credentials.
My files are stored on a Synology NAS with an SMB (cifs) share called media, files in Music/Flac.
Not sure what level of detail you need, but that’s the short version.
And then that allows you to play a file from your local NAS to a media player/speaker via HA by calling it via the /local/ path?
I always thought that wasn’t possible. I tried to do it when I first started with HA a couple of years ago trying to play a local mp3 to a chromecast audio and it wouldn’t work. So I had to store the file off site in a dropbox account and play the file from there. I haven’t heard that has changed so if you can do that it surprises me.
just for completeness and in case I’m missing something obvious would you also mind sharing the way you call the media player service to play that file from your local source?
The speaker is a Pioneer DLNA type, but as I said I can use BubbleUPnp as a renderer on my Android phone and stream to it as well. Not sure about streaming to a local speaker using the local path rather than a URL as I don’t have a speaker attached to my Raspberry Pi.
Just testing as I am new to HA, so currently it’s just a script, invoked via a badge.
Lemme tell you kind folks why playback of M3U playlists doesn’t work at the moment with the local media source.
Home Assistant tells the media player via UPnP play this URL please. That would be the correct URL of the M3U playlist — something like http://1.2.3.4:8080/media/local/myplaylist.m3u.
To this URL, Home Assistant appends a temporary cookie that looks kinda like this: ?authSig=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJiNDRjMjhlYzdkNjU0Zjg0OWNkYzg5MTIxZTBkODlhNSIsInBhdGgiOiIvbWVkaWEvbWVkaWEvQWxhcm0vVGhlIGJlc3Qgb2YgVUI0MCB2b2x1bWUgdHdvLm0zdSIsInBhcmFtcyI6e30sImlhdCI6MTY3NTgxMjk4MywiZXhwIjoxNjc1ODk5MzgzfQ.ZXN_tO1P7vvEpBmXOZ7ruwpzCRzTYSh792fV_h50qeA. This is an authorization cookie that can be used by the media player to retrieve this (otherwise HTTP/1.1 401 Unauthorized URL).
(We’ll assume your player supports M3U playlists and supports relativizing URLs from the playlist, all that good stuff — but you can’t assume this, you actually have to check with tcpdump in the wire.)
Anyway. The media player retrieves the URL. Yay! Home Assistant kindly serves it to them. Let’s assume the first item is Max Mix 2013 by Toni Peret.mp3 and promptly proceeds to retrieve the first item on the list. The next thing your player does is retrieve http://1.2.3.4:8080/media/local/Max%20Mix%202013%by%Toni%Peret.mp3.
Ordinarily — as in, with any UPnP server — this would work swell. But Home Assistant responds HTTP/1.1 401 Unauthorized!
Why? What gives?
Simply! Because the player did not append this ?authSig= cookie to the URL! The player has no way to know this is needed, there’s no spec to do this, and the player can’t just randomly append query string parameters to an UPnP-server-served URL just because.
Thus, the correct fix in the context of media_player.play_media is to do the following on the Home Assistant side when serving any M3U file to the UPnP (or any HTTP-based) player:
If any line in the M3U file refers to a media file in the same media source (it’s a path relative to it, effectively), urlencode the path in that line, and for good measure make it fully absolute to the Home Assistant URL (urljoin).
If the previous step actually changes any of the lines of the M3U file to produce a tentatively valid URL within the Home Assistant media source, then each changed line needs to get a valid ?authSig=<cookie> tacked at the end (basically a cookie that makes a valid URL).
Serve the M3U file as modified, not as it was originally.
Ensure that the authSig cookies generated in step 2 are all valid for an extended period of time (you like to backtrack in your playlist sometimes? so do I!)
Effectively, your act of calling media_player.play_media with a local media M3U needs to effectively grant permission to the media player to retrieve all local media URLs pointed at by the M3U.
That’s a fix that needs to be implemented in Home Assistant, no two ways about it. That task will probably fall to a volunteer and be reviewed by the owners of the local media_source component.