Menu

Internet Radio Player on Raspberry Pi

I still remember the day I started to make an android app for my mother-in-law to listen to internet radio because the place she lived received has poor FM radio broadcast signal. Why I needed to bother to code an app instead of using an off-the-shelf app is because my old mother-in-law is not versatile enough to play with the andriod UI. So my app is simply there is power on / power charge, it will start automatically. When there is no power charge, it will sleep automatically after a certain time-out (via BroadcastReceiver to receive the POWER_CONNECTED and POWER_DISCONECTED events). So she could simply use a power switch to turn on/off the app.

I used the MediaPlayer android object as the main part of the program. Yes, it is an easy-to-use object and I do not need to bother to handle the http download, mp3 conversion and sound playing logic. However, problem occurred when I use the app on site because there is transient (but now always) wifi stability problem. It seems that MediaPlayer object cannot handle the error in a very graceful manner. (I have already handled all the documented states of the object and capture all the exceptions!). When there was wifi problem, the app simply played on sound (and then forever). So far, what I could do is to ask my mother-in-law to switch off the charging and wait a few minutes and turn-on the charger again. But this was really inconvenient.

Years passed now and my mother-in-law has also died. But the idea of how to build a robust internet radio app is always in my mind. Recently I still to study the idea to build this app on my Raspberry Pi (which is has already wifi, and a built-in ear-phone jack (not of hifi quality but okay for internet radio).

This time, I nearly started from scratch (not really). I use libcurl for the http protocol, libmpg123 for the mp3 conversion and alsa (libasound) for the sound playing. For libcurl, I used the multi interface because it allows time-out handling. The program codes are not long after all these logic implementation. Most of the time I have spent is on the studying of API and choose the right ones because I have not used these libraries before). The name of the only C file is 'pi_rthk.c' because it played RTHK. I have also tested the problem for other internet radio URL's.

Posted by WH C 2021-10-10

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.