Post

Replies

Boosts

Views

Activity

MusicKit Artwork url
Hi, I'm trying out the beta for music kit. In the current version of my app, my widget can show multiple albums. I preload the images of the album covers. In the beta's the url that is returned for the artwork starts with: "musickit://", which does not work with URLSession. How can I preload the data using the new url scheme? Current code:     func fetchArtworkFor (musicID: MusicItemID, url : URL?) async throws -> UIImage? {         guard let url = url else {             return nil         }         let urlRequest = URLRequest (url: url)         let data = try await URLSession.shared.data(for: urlRequest)         let image = UIImage(data: data.0)         return image     } // Some other function         for album in albumsToShow {             if let url = album.artwork?.url(width: context.family.imageHeight, height: context.family.imageHeight), let image = try? await fetchArtworkFor(musicID: album.id, url:url) {                 images[album] = image             }         }
2
1
1.4k
Jun ’22
Play songs from library
Hello, I was trying to use the new ApplicationMusicPlayerController with an album from the music library. In my test code I am searching for the artist "LUWTEN" in my personal library. In my personal library there are two albums that will be found. When I try to play the first album I will get the error MSVEntitlementUtilities - Process .. PID[648] - Group: com.apple.private.tcc.allow - Entitlement: kTCCServiceMediaLibrary - Entitled: NO - Error: (null). Is there a way to play library music with the new ApplicationMusicPlayerController?     func searchLuwten () {         struct MyAlbums : Codable {             let results : Result         }                  struct Result : Codable {             let libraryAlbums : Albums             enum CodingKeys: String, CodingKey {                 case libraryAlbums = "library-albums"             }         }         struct Albums : Codable {             let href : String             let data : [LibraryAlbum]         }                  struct LibraryAlbum : Codable, PlayableMusicItem {             let id : MusicItemID             let attributes : Attributes                          var playParameters: PlayParameters? {                 attributes.playParams             }         }                  struct Attributes : Codable {             let name : String             let playParams : PlayParameters         }                  detach {             let term = "LUWTEN"             var components = URLComponents()             components.scheme = "https"             components.host   = "api.music.apple.com"             components.path   = "/v1/me/library/search"             components.queryItems =  [                 URLQueryItem (name: "term", value: term),                 URLQueryItem (name: "types", value: "library-albums")             ]                          guard let url = components.url else {                 return             }                          let dataRequest = MusicDataRequest(urlRequest: URLRequest(url: url))             let dataResponse = try await dataRequest.response()                          let decoder = JSONDecoder()             let albumResponse = try decoder.decode (MyAlbums.self, from: dataResponse.data)             let player = ApplicationMusicPlayer.shared             player.setQueue (with: albumResponse.results.libraryAlbums.data[0])             player.play()                      }     }
5
0
1.6k
Jul ’21