oleksiikolomiietssnapp/mediabridge
A Swift bridge for MPMediaLibrary integration.
Installation
Add MediaBridge to your project via Swift Package Manager:
dependencies: [
.package(url: "https://github.com/oleksiikolomiietssnapp/MediaBridge.git", from: "0.8.0")
]Quick Start
let library = MusicLibrary()
// Optional: Check or request authorization first
if library.authorizationStatus != .authorized {
try await library.requestAuthorization()
}
// Fetch songs
let songs = try await library.songs()
// Fetch albums
let albums = try await library.albums()
// Fetch artists
let artists = try await library.artists()
// Fetch playlists
let playlists = try await library.playlists()For SwiftUI, inject via environment:
extension EnvironmentValues {
@Entry var library: MusicLibraryProtocol = MusicLibrary()
}
@Environment(\.library) var library
// Songs sorted by skip count
let songs = try await library.songs(sortedBy: \MPMediaItem.skipCount, order: .reverse)
// Albums sorted by track count
let albums = try await library.albums(sortedBy: \MPMediaItemCollection.count, order: .reverse)
// Filter by genre
let rockSongs = try await library.songs(matching: .genre("Rock"), comparisonType: .equalTo)Both the service layer and authorization manager use production implementations by default (.live), but you can provide custom implementations for testing or specialized behavior.
Migration
0.7.0
albumArtistIDpredicate case now takesUInt64instead ofString. Update any call sites using.albumArtistID("...")to pass a numeric ID instead.fetchSongs,fetchSong, andfetchare no longer protocol requirements. They remain available as deprecated extension methods but conformers no longer need to implement them.
Documentation
For more information visit Documentation.
Contributing
Please see CONTRIBUTING.md for guidelines on how to contribute to MediaBridge.
License
MIT License - see the LICENSE file for details.
Package Metadata
Repository: oleksiikolomiietssnapp/mediabridge
Default branch: main
README: README.md