This repo is the finalized, ready-to-run version of the demo app from my article:
Mastering Lock Screen & Now Playing Metadata in iOS with MPNowPlayingInfoCenter
When you build audio playback into an iOS app, the part that trips everyone up is what happens after the phone locks or the app goes in the background: a blank lock screen, no artwork, non interactive player UI, while apps like Spotify and Apple Music sit there looking perfect.
The article walks through closing that gap with MPNowPlayingInfoCenter one system-wide dictionary that the lock screen, Control Center, CarPlay, Apple Watch, and AirPods all read from. It covers:
- The three prerequisites that decide whether iOS shows your player at all: the Background Modes (Audio) capability, an
AVAudioSessionset to.playback, and registered handlers onMPRemoteCommandCenter. Miss any one of them and the API fails silently. - The snapshot model for the progress bar. You don't push elapsed time every second. You set elapsed time + playback rate + duration once per state change (play, pause, seek), and the system animates the scrubber on its own.
- Artwork done lazily with
MPMediaItemArtworkand its request handler, so nothing blocks. - Cleanup and gotchas. Clearing stale info, why the simulator lies about Now Playing behavior, and how
AVPlayerViewControllerwill overwrite your dictionary if you don't pick an owner.
A minimal SwiftUI player, built entirely around the article:
- Plays a bundled
sample.mp3in the background with play/pause and a scrub slider - Reads the file's full embedded metadata using the modern async
AVAssetloading APIs — title, artist, album, and artwork for the header, plus every raw ID3 tag listed below the player so you can see exactly what your file carries - Publishes that metadata to
MPNowPlayingInfoCenter, giving you a fully interactive player on the lock screen and in Control Center — artwork, title, a live scrubber you can drag, and working play/pause
- Open the project in Xcode and select your target.
- Signing & Capabilities → + Capability → Background Modes → check Audio, AirPlay, and Picture in Picture. Without this, audio stops the moment the phone locks.
- Make sure
sample.mp3is in the bundle with the target checked. - Run on a real device. Now Playing behavior on the simulator ranges from flaky to absent — don't debug against it.
Play the audio, lock the phone, and your metadata should be sitting on the lock screen with working controls.
The bundled sample.mp3 comes from my own collection of test files:
Audio sample files — mzeeshan.me
Use a file with real embedded tags when testing metadata pipelines. The collection has MP3, M4A and FLAC variants with proper metadata embedded for exactly this kind of testing.
The app icon in this project was generated with another tool of mine:
App Icon Generator — mzeeshan.me
It's a free, browser-based generator that goes beyond resizing providing drop-in replacement. You compose the icon itself from a background plus a foreground layer (an image, clip art from the React Icons library, or styled text), preview it live in real device frames, and download a project-ready ZIP with the correct AppIcon.appiconset structure for Xcode. Android adaptive icons are supported too if you're building cross-platform.
Best for demo or an MVP, it's a two-minute fix for the default placeholder grid icon, which is exactly what I used it for here.
- Xcode 15+
- iOS 16+ deployment target (uses the async
AVAsset/AVMetadataItemloading APIs) - A physical device for lock screen testing