Published: Feb 28, 2021 by Simon Schneider
I went to visit my parents, during the pandemic, it didnt happen as often as before. We sat together for dinner and my dad told me about his broken hi-fi set. The CD-Player was broken again and he wanted to fix it by switching the laser unit. During the discussion i asked him why he even needed the CD-Player anyways? His answer was simple, he doesnt! His hi-fi set, tries to read CDs when powered on. Since the CD-Player is broken and makes weird noises, even if you dont play CDs. He used his hi-fi set only to listen to a webradio stream, which was played on an external web radio. This external device also has speakers, but as usual they are crappy. So we thought about it, opened up the hi-fi set and disconnected the CD-Player. As the hi-fi set was open and parts scattered all around us, i thought about placing a raspberry pi into the hi-fi set, connect it to the aux port and let it play the radio stream. An initial prototyp was build quickly. I controlled a vlc player with ssh which was the quickest solution i have thought of. But since i am pretty sure my dad wouldnt want to login to the pi with SSH every morning just to turn on the radio, i had to build something better! Since the raspberry pi was already placed inside of the hi-fi set, i could only access it over ssh. But since i have VPN access to the raspberry pi, i also could develop stuff from home and deploy it to the pi.
Since i had no pyhsical access to the raspberry pi, i thought about having a web interface instead of a IR1 remote control. The web interface should be accessible from a smartphone, because my dad would not use his laptop before he had his first coffee. And i didnt want to use any external service. So lets sum it up:
- Web UI for control
- MP3 Streams provide the audio data
- Multiple Stations should be available
I thought about go at first, but i didnt find a good audio library for go. A prototype with java worked good, so i started to setup a project with spring boot, kotlin and sqlite. This allowed me to create a simple rest api and use the native java audio framework. After a few setbacks my curl requests worked and i could start and stop mp3 streams.
At this stage i started the development of the Web Interface, which is build with angular. I dont think Angular is the best choice for this task, but i already had some code from other projects and i like the angular material design library.
Packed into a deb file, i installed rayd.io (at this point the name was decided) on the raspberry pi at my dads home. I send him the link to the Web Interface and he tried to use it. The SSE endpoint created some problems since the current state was not synced to the Web Interface correctly but the audio worked fine.
After this intial version, i tried to improve it a bit. I added a display for the currently playing title and tried to fix the SSE Endpoint, which partly worked. In the frontend i made rayd.io compatible to apple-mobile-web-app requirements.
Also i think its anoying that on a reconnect to the mp3 stream some content is dupplicated. The stream implementation in rayd.io could try to find the matching end of the old stream and match it with the start of the new stream. But this could also lead to false-positives.
I talked to my dad a few days ago and he is pretty happy with his new hi-fi set. He likes it and uses rayd.io every day! I also use rayd.io, but i have an raspberry-pi connected to my tv which plays my favorite station. You can also try out rayd.io today, simply install it on your raspberry pi and add your favorite radio station.