Streaming apps give you endless choice: playlists, queues, a skip button on every track. FM radio gave you none of that. You tuned in and listened to whatever was playing. I wanted that feeling back, so I built FmMusic: pick a few genres on first launch, and each one becomes a live channel. No account, no skipping, just press play. This article walks through how the app is built, and the design decisions that matter most.

Why live streams make the idea easy

The "no skip" rule is not a feature I had to build. Internet radio stations are live streams, so there is no next track to jump to. The app only has to avoid pretending otherwise: no skip button in the UI, and no skip commands on the lock screen either (more on that in step 5).

The architecture

I used MVVM with a strict split:

FmMusic/ Models/ Genre, RadioStation Services/ RadioBrowserService, AudioPlayerService ViewModels/ OnboardingViewModel, HomeViewModel, PlayerViewModel Views/ OnboardingView, HomeView, NowPlayingView, MiniPlayerBar 

Services talk to the outside world (network, audio). ViewModels talk to services and expose state. Views only render state. No view ever touches URLSession or AVPlayer, which keeps each layer easy to change on its own.

1. Pick a free data source

I needed a catalog of live stations that is free and needs no account. Radio-Browser fits: it is open, needs no API key, and every station carries genre tags, so "genre → channel" maps directly onto one endpoint:

GET /json/stations/bytagexact/{tag}?order=votes&reverse=true&hidebroken=true

Sorting by votes puts the stations people actually use first. Two things to know: the project asks apps to send a descriptive User-Agent, and because the catalog is community-maintained, the data is messy. Stations go offline and fields are not always typed consistently. The next steps handle both.

2. Model genres and stations

A genre is just a display name, an SF Symbol and the exact Radio-Browser tag to search for. I started with twelve and kept only tags that reliably return good stations.

struct Genre: Identifiable, Hashable, Codable { let id: String let displayName: String let tag: String // exact Radio-Browser tag let symbolName: String // SF Symbol static let starterSet: [Genre] = [ Genre(id: "jazz", displayName: "Jazz", tag: "jazz", symbolName: "music.quarternote.3"), Genre(id: "lofi", displayName: "Lo-Fi", tag: "lofi", symbolName: "waveform"), Genre(id: "rock", displayName: "Rock", tag: "rock", symbolName: "guitars"), // ...nine more ] } 

The station model needs more care. Numbers sometimes arrive as strings and missing URLs arrive as empty strings, so I decode defensively. One malformed station should never fail the whole batch.

struct RadioStation: Identifiable, Codable, Hashable { let id: String let name: String let streamURL: URL? let tags: String let votes: Int let lastCheckOK: Bool enum CodingKeys: String, CodingKey { case id = "stationuuid" case name, tags, votes case streamURL = "url_resolved" case lastCheckOK = "lastcheckok" } init(from decoder: Decoder) throws { let c = try decoder.container(keyedBy: CodingKeys.self) id = try c.decode(String.self, forKey: .id) name = try c.decode(String.self, forKey: .name) tags = (try? c.decode(String.self, forKey: .tags)) ?? "" streamURL = URL(string: (try? c.decode(String.self, forKey: .streamURL)) ?? "") votes = Self.flexibleInt(c, .votes) lastCheckOK = Self.flexibleBool(c, .lastCheckOK) } private static func flexibleInt(_ c: KeyedDecodingContainer<CodingKeys>, _ key: CodingKeys) -> Int { if let v = try? c.decode(Int.self, forKey: key) { return v } if let s = try? c.decode(String.self, forKey: key) { return Int(s) ?? 0 } return 0 } private static func flexibleBool(_ c: KeyedDecodingContainer<CodingKeys>, _ key: CodingKeys) -> Bool { if let v = try? c.decode(Bool.self, forKey: key) { return v } if let v = try? c.decode(Int.self, forKey: key) { return v == 1 } if let s = try? c.decode(String.self, forKey: key) { return s == "1" || s.lowercased() == "true" } return false } } 

url_resolved is the stream URL after redirects, which is what you want to hand to AVPlayer.

3. Fetch stations with mirror failover

Radio-Browser runs several mirror servers, and any one of them can be down. The service tries a short list in order and remembers whichever one worked last, so the next request goes there first. Making it an actor keeps that remembered mirror safe across concurrent calls.

actor RadioBrowserService { private let mirrors = [ "https://de1.api.radio-browser.info", "https://at1.api.radio-browser.info", "https://nl1.api.radio-browser.info" ] private let userAgent = "FmMusic/1.0 (iOS)" private var workingMirror: String? func fetchStations(forTag tag: String, limit: Int = 20) async throws -> [RadioStation] { let encoded = tag.addingPercentEncoding(withAllowedCharacters: .urlPathAllowed) ?? tag let path = "/json/stations/bytagexact/\(encoded)?order=votes&reverse=true&hidebroken=true&limit=\(limit)" let stations: [RadioStation] = try await request(path: path) return stations.filter { $0.lastCheckOK && $0.streamURL?.scheme == "https" } } private func request<T: Decodable>(path: String) async throws -> T { var lastError: Error = URLError(.cannotConnectToHost) var ordered = mirrors if let good = workingMirror { ordered.removeAll { $0 == good } ordered.insert(good, at: 0) } for base in ordered { guard let url = URL(string: base + path) else { continue } var req = URLRequest(url: url) req.setValue(userAgent, forHTTPHeaderField: "User-Agent") req.timeoutInterval = 8 do { let (data, response) = try await URLSession.shared.data(for: req) guard let http = response as? HTTPURLResponse, (200..<300).contains(http.statusCode) else { throw URLError(.badServerResponse) } let decoded = try JSONDecoder().decode(T.self, from: data) workingMirror = base return decoded } catch { lastError = error // try the next mirror } } throw lastError } } 

I also keep only stations whose last uptime check passed and whose stream is https. That avoids App Transport Security exceptions in Info.plist. It costs some stations, but it keeps version one simple.

4. Wrap AVPlayer in a service

All audio lives in one ObservableObject that exposes a small state enum. The UI never talks to AVPlayer directly.

enum PlaybackState: Equatable { case idle, buffering, playing, paused case failed(String) } @MainActor final class AudioPlayerService: ObservableObject { @Published private(set) var state: PlaybackState = .idle @Published private(set) var currentStation: RadioStation? private var player: AVPlayer? private var statusObserver: NSKeyValueObservation? private var cancellables = Set<AnyCancellable>() init() { configureAudioSession() configureRemoteCommands() observeInterruptions() } func play(station: RadioStation) { guard let url = station.streamURL else { state = .failed("No stream URL for \(station.name)") return } currentStation = station state = .buffering let item = AVPlayerItem(url: url) statusObserver?.invalidate() statusObserver = item.observe(\.status, options: [.new]) { [weak self] item, _ in Task { @MainActor in switch item.status { case .readyToPlay: self?.state = .playing case .failed: self?.state = .failed(item.error?.localizedDescription ?? "Stream failed") default: break } } } if let player { player.replaceCurrentItem(with: item) } else { player = AVPlayer(playerItem: item) } player?.play() updateNowPlayingInfo() } func pause() { player?.pause(); state = .paused; updateNowPlayingInfo() } func resume() { player?.play(); state = .playing; updateNowPlayingInfo() } func togglePlayPause() { switch state { case .playing, .buffering: pause() default: resume() } } private func configureAudioSession() { do { try AVAudioSession.sharedInstance().setCategory(.playback, mode: .default) try AVAudioSession.sharedInstance().setActive(true) } catch { state = .failed("Audio session error: \(error.localizedDescription)") } } } 

The .playback category is what lets audio continue when the screen locks. Without it, audio stops when the screen locks and also follows the silent switch.

A radio app has to behave well around the rest of the phone. Pause on phone calls and Siri, resume when iOS says it should, and pause when headphones are unplugged so the music doesn't suddenly play out of the speaker:

private func observeInterruptions() { NotificationCenter.default.publisher(for: AVAudioSession.interruptionNotification) .receive(on: DispatchQueue.main) .sink { [weak self] note in guard let self, let raw = note.userInfo?[AVAudioSessionInterruptionTypeKey] as? UInt, let type = AVAudioSession.InterruptionType(rawValue: raw) else { return } switch type { case .began: pause() case .ended: let opts = note.userInfo?[AVAudioSessionInterruptionOptionKey] as? UInt ?? 0 if AVAudioSession.InterruptionOptions(rawValue: opts).contains(.shouldResume) { resume() } @unknown default: break } } .store(in: &cancellables) NotificationCenter.default.publisher(for: AVAudioSession.routeChangeNotification) .receive(on: DispatchQueue.main) .sink { [weak self] note in guard let raw = note.userInfo?[AVAudioSessionRouteChangeReasonKey] as? UInt, AVAudioSession.RouteChangeReason(rawValue: raw) == .oldDeviceUnavailable else { return } self?.pause() } .store(in: &cancellables) } 

These notifications are not guaranteed to arrive on the main thread, so .receive(on: DispatchQueue.main) matters here. The service is @MainActor and updates published state.

5. Lock screen controls, with no skip

This is where the "FM" idea is enforced at the system level. Register only play and pause, and explicitly disable everything else:

**private func configureRemoteCommands() {
let center = MPRemoteCommandCenter.shared()
center.playCommand.addTarget { [weak self] _ in self?.resume(); return .success }
center.pauseCommand.addTarget { [weak self] _ in self?.pause(); return .success }
center.togglePlayPauseCommand.addTarget { [weak self] _ in self?.togglePlayPause(); return .success }

center.nextTrackCommand.isEnabled = false center.previousTrackCommand.isEnabled = false center.changePlaybackPositionCommand.isEnabled = false 

}

private func updateNowPlayingInfo() {
guard let station = currentStation else { return }
MPNowPlayingInfoCenter.default().nowPlayingInfo = [
MPMediaItemPropertyTitle: station.name,
MPNowPlayingInfoPropertyIsLiveStream: true,
MPNowPlayingInfoPropertyPlaybackRate: state == .playing ? 1.0 : 0.0
]
}**

Marking the item as a live stream tells iOS to show a live indicator instead of a progress bar. With the commands disabled, there is no skip button in Control Center and no skip gesture on headphones either.

Then turn on Signing & Capabilities → Background Modes → Audio, AirPlay, and Picture in Picture. Skip this and playback stops as soon as the app is backgrounded.

6. Onboarding with no account

The whole onboarding is a genre picker. The result is stored in UserDefaults, so there is no backend and no sign-up.

@MainActor final class OnboardingViewModel: ObservableObject { @Published var selectedGenreIDs: Set<String> = [] let availableGenres = Genre.starterSet var canContinue: Bool { !selectedGenreIDs.isEmpty } func toggle(_ genre: Genre) { if selectedGenreIDs.contains(genre.id) { selectedGenreIDs.remove(genre.id) } else { selectedGenreIDs.insert(genre.id) } } func finishOnboarding() { UserDefaults.standard.set(Array(selectedGenreIDs), forKey: "selectedGenreIDs") UserDefaults.standard.set(true, forKey: "hasCompletedOnboarding") } static func hasCompletedOnboarding() -> Bool { UserDefaults.standard.bool(forKey: "hasCompletedOnboarding") } static func loadSelectedGenres() -> [Genre] { let ids = Set(UserDefaults.standard.stringArray(forKey: "selectedGenreIDs") ?? []) return Genre.starterSet.filter { ids.contains($0.id) } } } 

The "Start Listening" button is disabled until at least one genre is selected. The app entry point routes between the two flows, and owns the single audio service so playback never depends on which screen is visible:

@main struct FmMusicApp: App { @StateObject private var audioPlayer = AudioPlayerService() @State private var hasCompletedOnboarding = OnboardingViewModel.hasCompletedOnboarding() var body: some Scene { WindowGroup { if hasCompletedOnboarding { HomeView(audioPlayer: audioPlayer) } else { OnboardingView { hasCompletedOnboarding = true } } } } } 

7. Turn genres into channels

Each selected genre resolves to one channel: its top-voted live station. If one genre fails to load, the others still show.

Related posts