About this project
MediaBridge is a Swift bridge for MPMediaLibrary integration, distributed as a Swift Package. It targets iOS 15.0+ and visionOS 1.0+, and requires Swift 6.0 / Xcode 16 or later; CI builds against Swift 6.0 and runs tests on Swift 6.1 through 6.4.
The package wraps Apple's MediaPlayer framework with a higher-level service layer. A MusicLibrary type exposes async methods for fetching songs, albums, artists, playlists, genres, composers, compilations, podcasts and audiobooks, plus A–Z index sections via songSections(). A changes async sequence lets callers re-fetch when the library changes.
A key-path query builder supports typed models: queries can filter (for example on isCloudItem), sort by key paths such as playCount or releaseDate, and limit results. The README notes a public retroactive conformance Optional: Comparable where Wrapped: Comparable so optional key paths can be sorted, and warns that a conflicting conformance from another dependency would need disambiguation.
Playlist management is included: callers can fetch a playlist by id or create one from PlaylistMetadata, then add fetched items to it. On iOS, a mediaPicker SwiftUI modifier presents the system picker and returns selected songs.
For SwiftUI, the library can be injected through the environment; examples show sorting songs by skip count, albums by track count, and filtering songs by genre with a comparison type. The service layer and authorization manager default to production (.live) implementations, with custom implementations possible for testing or specialized behavior. Authorization can be requested explicitly, and fetches request access on their own; the README stresses that NSAppleMusicUsageDescription must be present in Info.plist or iOS terminates the app on first library access.
Installation is via Swift Package Manager with a version requirement starting at 0.14.0. The README documents migration notes for 0.11.0 (service protocol reduced to items(_:) and collections(_:) taking a MediaQueryRequest; previews are MusicLibrary instances via .preview(...); denied previews now throw) and 0.7.0 (albumArtistID predicate takes UInt64; fetchSongs, fetchSong and fetch are no longer protocol requirements but remain as deprecated extension methods). Documentation is hosted on the Swift Package Index, and the project is MIT licensed with contribution guidelines in CONTRIBUTING.md.
Comments
0 Rating appears after 10 ratings
Sign in to join the discussion.