What's New / Media, Audio & Capture

What's new in MusicKit

+6 NewiOS · macOS · tvOS · watchOS

MusicKit gives apps access to the Apple Music catalog and a user's library, including catalog requests, playback, and music item models like Song, Track, and MusicVideo.

The 27 SDK adds 6 APIs with no deprecations or removals. A new PickableMusicItem protocol is adopted by music item types including Song, Track, and MusicVideo. MusicCatalogResourceResponse gains an item property, and there is a new View entry point for music item selection.

New

6
extension

MusicVideo

NewiOS
extension MusicVideo : PickableMusicItem
Declaration
extension MusicVideo : PickableMusicItem {
}
protocol

PickableMusicItem

NewiOS
public protocol PickableMusicItem : MusicItem, Decodable, Encodable, Hashable

A protocol for the MusicKit item type that can be selected in the music picker.

Declaration
public protocol PickableMusicItem : MusicItem, Decodable, Encodable, Hashable {
}
extension

Song

NewiOS
extension Song : PickableMusicItem
Declaration
extension Song : PickableMusicItem {
}
extension

Track

NewiOS
extension Track : PickableMusicItem
Declaration
extension Track : PickableMusicItem {
}
extension

View

NewiOS
extension View
Declaration
extension View {

    /// Presents a music picker to select items from the Apple Music catalog and the user’s music library.
    ///
    /// - Parameters:
    ///   - isPresented: The binding to whether the music picker should be shown.
    ///   - title: The title to be shown in the navigation bar.
    ///   - selection: The selected music item.
    ///
    /// Example:
    /// ```swift
    /// struct MusicPickerButton: View {
    ///     @State private var isShowingMusicPicker = false
    ///     @State private var selectedSong: Song?
    ///
    ///     var body: some View {
    ///         Button("Pick a song") {
    ///             isShowingMusicPicker = true
    ///         }
    ///         .musicPicker(isPresented: $isShowingMusicPicker, selection: $selectedSong)
    ///     }
    /// }
    /// ```
    @MainActor @preconcurrency public func musicPicker<Selection>(isPresented: Binding<Bool>, title: Text? = nil, selection: Binding<Selection?>) -> some View where Selection : PickableMusicItem


    /// Presents a music picker to select items from the Apple Music catalog and the user’s music library.
    ///
    /// - Parameters:
    ///   - isPresented: The binding to whether the music picker should be shown.
    ///   - title: The title to be shown in the navigation bar.
    ///   - selection: The selected music items.
    ///
    /// Example:
    /// ```swift
    /// struct MusicPickerButton: View {
    ///     @State private var isShowingMusicPicker = false
    ///     @State private var selectedSongs: [Song] = []
    ///
    ///
    ///     var body: some View {
    ///         Button("Pick one or more songs") {
    ///             isShowingMusicPicker = true
    ///         }
    ///         .musicPicker(isPresented: $isShowingMusicPicker, selection: $selectedSongs)
    ///         .onChange(of: selectedSongs) { oldValue, newValue in
    ///             let delta = newValue.count - oldValue.count
    ///             print("You selected \(delta) new tracks!")
    ///         }
    ///     }
    /// }
    /// ```
    @MainActor @preconcurrency public func musicPicker<Selection>(isPresented: Binding<Bool>, title: Text? = nil, selection: Binding<[Selection]>) -> some View where Selection : PickableMusicItem


    /// Presents a music picker to select items from the Apple Music catalog and the user’s music library.
    ///
    /// - Parameters:
    ///   - isPresented: The binding to whether the music picker should be shown.
    ///   - title: The title to be shown in the navigation bar.
    ///   - selection: The selected music items.
    ///
    /// Example:
    /// ```swift
    /// struct MusicPickerButton: View {
    ///     @State private var isShowingMusicPicker = false
    ///     @State private var selectedSongs: MusicItemCollection<Song> = []
    ///     private var title = "Add to Playlist"
    ///
    ///     var body: some View {
    ///         Button("Pick one or more songs") {
    ///             isShowingMusicPicker = true
    ///         }
    ///         .musicPicker(
    ///             isPresented: $isShowingMusicPicker,
    ///             title: Text(title), 
    ///             selection: $selectedSongs
    ///         )
    ///         .onChange(of: selectedSongs) { oldValue, newValue in
    ///             let delta = newValue.count - oldValue.count

Truncated.

func

MusicCatalogResourceResponse.item

NewiOSmacOStvOSwatchOS
public func item(for id: MusicItemID) -> MusicItemType?

Returns the item in this response that corresponds to the given identifier.

No APIs match your filter.

← More in Media, Audio & Capture