Building a Personal Radio Player for Android with Media3
I have an Icecast-style radio stream running on a Raspberry Pi at home, and I wanted a simple way to listen to it on my phone. Generic radio apps expect a directory of stations, and browser tabs die the moment the screen locks. What I needed was a small app that opens, plays my stream, keeps playing in the background, and works with a Bluetooth speaker. That is what IR- Radio does. It is a native Android app written in Kotlin, and this post covers how it is put together and what the choices taught me.
Why I built it
The stream is personal, so the app should be too. I did not want accounts, station lists or ads. I wanted one tap, or really zero taps, to start listening. The app launches and immediately plays the saved stream. The default is a Raspberry Pi address, and I wanted to be able to point the app somewhere else without rebuilding it. That last requirement ended up shaping a lot of the design.
What it does
- Autoplay on launch. The saved stream starts as soon as the app opens.
- Transport controls. Play/pause, plus a reconnect button that does a hard restart of the connection when the stream drops.
- Volume. An in-app slider and +/- buttons tied to the phone's music volume. Hardware volume buttons work as usual because the app uses the standard
STREAM_MUSICaudio channel. - Bluetooth output. Audio routes to a connected Bluetooth speaker or headphones through normal Android routing. The app shows whether the phone speaker or Bluetooth is active and has a shortcut into Android's Bluetooth settings.
- Background playback. Playback continues after leaving the app, with a persistent notification, lock-screen controls and Android's Live Updates media card.
- Now Playing info. If the stream server sends ICY/Shoutcast metadata (
StreamTitle), the current track appears in the app and in the notification. If the stream does not send it, the app shows "Live Stream". That is a property of the stream, not something the app can fix. - Editable stream URL. An Edit Stream URL dialog, also reachable by long-pressing the station name, lets me change the station name and URL. The new stream starts playing immediately and is used on future launches.
How it works
The app is built on Media3 and has three main pieces.
PlaybackService
This is a MediaSessionService that owns a single ExoPlayer and a MediaSession. Putting the player in a service rather than an activity is the key decision for any audio app. The activity can be destroyed and recreated, but playback carries on. Because Media3 handles the session, I did not write custom notification code or broadcast receivers. The system media notification, lock-screen controls, the Live Updates card and Bluetooth headset play/pause buttons all come from the session.
MainActivity
The activity connects to the service through a MediaController and only ever talks to the player through that controller. It never touches ExoPlayer directly. This keeps a clean boundary: the UI sends commands and observes state, and the service decides what actually happens. It also means playback lifetime does not depend on the activity lifecycle.
RadioPrefs
A thin wrapper around SharedPreferences that stores the current stream URL and station name. The defaults live in a Constants.kt file and are used only the first time the app runs. After that the app reads from RadioPrefs, which is what makes the in-app editing work without a code change or reinstall.
Build setup
The project targets Android 7.0 (API 24) and newer, with compileSdk and targetSdk 37. It builds with JDK 17 and Gradle 9.x, using AGP 9's built-in Kotlin support, so no separate Kotlin Gradle plugin is needed. The local.properties file with the SDK path is machine-specific and not committed.
What I learned
Let the platform do the work
My first instinct for background audio was to build a notification and handle media buttons myself. Using MediaSessionService removed all of that. If you are building an audio app on Android, start from a media session and see how much you get before writing custom code.
Cleartext traffic is a real trade-off
Android blocks plain http:// by default. In version 1.0 I allowed cleartext only for raspberrypi.local through the network security config. Once the stream URL became editable in version 1.2, that scoped rule no longer made sense, since I could not know the host in advance. I broadened the config to allow cleartext for any host. That is acceptable for a personal utility used on my own network, but it means the app does not enforce HTTPS for whatever URL you give it. I documented that in the README because it is the kind of decision a future reader should not have to discover.
Runtime configuration beats build-time constants
The first version hardcoded the stream. Moving the value into preferences, with the constant as a first-run default, was a small change that made the app far more usable. It also forced me to revisit the network security rules, which was the right consequence to surface early.
Metadata depends on the server
Showing the current track relies on the stream sending ICY metadata. Handling the missing case gracefully, with a plain "Live Stream" label, matters more than the happy path, because many streams do not send it.
Conclusion
IR- Radio is a small app, but it covers the core pieces of a well-behaved Android audio player: a service-owned player, a controller-based UI, system-managed notifications and Bluetooth routing, and user-editable configuration. If you want to build something similar, I would start with Media3's session service, keep the UI talking only to a controller, and think early about how configurable the stream source needs to be, because that decision affects your network security settings too.