-
Explore more content with MusicKit
Discover how you can enhance and personalize your app using MusicKit. We'll take you through the latest additions to the MusicKit framework and explore how you can bring music content to your app through requests, metadata, and more.
Recursos
Vídeos relacionados
WWDC22
WWDC21
-
Buscar neste vídeo...
-
-
4:20 - Existing catalog search request
// Loading catalog search top results var searchRequest = MusicCatalogSearchRequest( term: "Hello", types: [ Artist.self, Album.self, Song.self ] ) let searchResponse = try await searchRequest.response() print("\(searchResponse)") -
4:44 - Loading catalog search top results
// Loading catalog search top results var searchRequest = MusicCatalogSearchRequest( term: "Hello", types: [ Artist.self, Album.self, Song.self ] ) searchRequest.includeTopResults = true let searchResponse = try await searchRequest.response() print("\(searchResponse.topResults)") -
5:09 - Loading search suggestions
// Loading suggestions let request = MusicCatalogSearchSuggestionsRequest(term: "shaz") let response = try await request.response() print("\(response)") -
6:30 - Loading catalog top charts
// Loading catalog top charts. let request = MusicCatalogChartsRequest( kinds: [.dailyGlobalTop, .mostPlayed, .cityTop], types: [Song.self, Playlist.self] ) let response = try await request.response() print("\(response.playlistCharts.first)") -
8:10 - Loading audio variants
// Loading audio variants let album = … let detailedAlbum = try await album.with(.audioVariants) print("\(detailedAlbum.debugDescription)") -
9:09 - Showing currently playing audio variants
// Showing currently playing audio variants @ObservedObject var musicPlayerQueue = ApplicationMusicPlayer.shared.queue @ObservedObject var musicPlayerState = ApplicationMusicPlayer.shared.state var body: some View { if let currentEntry = musicPlayerQueue.currentEntry { VStack { MyPlayerEntryView(currentEntry) if musicPlayerState.audioVariant == .dolbyAtmos { Image("dolby-atmos-badge") } } } } -
10:28 - Loading recently played containers
// Loading recently played containers let request = MusicRecentlyPlayedContainerRequest() let response = try await request.response() print("\(response)") -
10:41 - Loading recently played songs
// Loading recently played songs let request = MusicRecentlyPlayedRequest<Song>() let response = try await request.response() print("\(response)") -
11:21 - Loading personal recommendations and printing first recommendation
// Loading personal recommendations let request = MusicPersonalRecommendationsRequest() let response = try await request.response() print("\(response.recommendations.first)") -
11:51 - Loading personal recommendations and printing second recommendation
// Loading personal recommendations let request = MusicPersonalRecommendationsRequest() let response = try await request.response() print("\(response.recommendations[1])") -
13:36 - Loading library playlists
@MainActor private func loadLibraryPlaylists() async throws { let request = MusicLibraryRequest<Playlist>() let response = try await request.response() self.response = response } -
14:23 - Displaying library playlists
List { Section(header: Text("Library Playlists").fontWeight(.semibold)) { ForEach(response.items) { playlist in PlaylistCell(playlist) } } } -
15:47 - Fetching all albums in the library
// Fetching all albums in the library let request = MusicLibraryRequest<Album>() let response = try await request.response() print("\(response)") -
16:38 - Fetching all compilations in the library
// Fetching all compilations in the library var request = MusicLibraryRequest<Album>() request.filter(matching: \.isCompilation, equalTo: true) let response = try await request.response() print("\(response)") -
17:08 - Fetching all dance compilations in the library
// Fetching all dance compilations in the library var request = MusicLibraryRequest<Album>() request.filter(matching: \.isCompilation, equalTo: true) request.filter(matching: \.genres, contains: danceGenre) let response = try await request.response() print("\(response)") -
17:29 - Fetching all downloaded dance compilations in the library
// Fetching all downloaded dance compilations in the library var request = MusicLibraryRequest<Album>() request.filter(matching: \.isCompilation, equalTo: true) request.filter(matching: \.genres, contains: danceGenre) request.includeDownloadedContentOnly = true let response = try await request.response() print("\(response)") -
18:29 - Fetching all albums sectioned by genre
// Fetching all albums sectioned by genre var request = MusicLibrarySectionedRequest<Genre, Album>() let response = try await request.response() print("\(response)") -
19:04 - Fetching all albums sectioned by genre sorted by artist name
// Fetching all albums sectioned by genre sorted by artist name var request = MusicLibrarySectionedRequest<Genre, Album>() request.sortItems(by: \.artistName, ascending: true) let response = try await request.response() print("\(response)") -
20:58 - Fetching relationships using the with method without a preferred source
// Fetching relationships using the with method let album = … let detailedAlbum = try await album.with(.tracks) print("\(album.tracks)") -
21:11 - Fetching relationships using the with method and a preferred source
// Fetching relationships using the with method let album = … let detailedAlbum = try await album.with(.tracks, preferredSource: .library) print("\(album.tracks)") -
22:09 - Adding a track to a playlist
Task { try await MusicLibrary.shared(add: selectedTrack, to: playlist) isShowingPlaylistPicker = false }
-