Environment: HACS + Python
Problem: Xiao Ai cannot play local songs or songs in Group Favorites
Solution: HACS + Http Server
Background: It is impossible to rush to the green bricks. DLNA has also been castrated. We can only save the country through curves.
Solution: Monitor Xiaoai events through HACS, push media links and play them randomly. See the flow chart below for details.
Article directory
1. Install HACS:
The steps are omitted and you can solve it by yourself. I pulled the official container homeassistant/home-assistant:latest on Synology.
2. Install HACS Xiaomi integration:
The steps are omitted and you can solve it by yourself. I searched and added it in the integration. Refer to the picture below to ensure that the speaker appears:
3. Debugging music playback
3.1 Debugging music playback in HACS developer tools
Refer to the picture below and prepare an mp3 URL link. It is best to connect directly. I can also test the redirection.
Steps: Developer tools-server-play media-select the entity-ID as the link address, select play
If everything goes well, you will hear music playing directly from the Xiaoai speaker, and you are 90% successful.
3.2 Build a random playlist
Our goal is to let Xiao Ai play all the music in our server. Just pushing an MP3 link is not enough.
I have tried many methods in this area. The final idea is to use python to write an http server:
1. When the user requests /playlist Immediately scan local audio files
2. Disorganize the order of files and generate an m3u8 playlist
3. Xiaoai reads and plays