I've finally been spending some time getting to know the MusicKit API, which is really nicely designed and will let me get rid of a ton of less efficient code as I start implementing it.
I'm used to hitting the /artists/{id}/view/latest-release API endpoint via a URLSession data task to return an artist's most recent release, if available. I see that it seems to be possible to return that information in a MusicCatalogResourceRequest, but the following code returns nil for me:
var request = MusicCatalogResourceRequest<Artist>.init(matching: \.id, equalTo: "35719")
request.properties = [.latestRelease]
do {
let response = try await request.response()
print(response.items.first?.latestRelease)
} catch {
print(error.localizedDescription)
}
In the code above, I've hardcoded the ID for an artist, but I've tried this in a for loop and it returns nil for every artist in my library. (By contrast, when adding .fullAlbums or .albums to the properties array, it does fetch that relationship).
When I construct a MusicDataRequest against the endpoint I'm used to hitting, it correctly returns the latest release. This is the code I'm using for that:
let request = MusicDataRequest(urlRequest: URLRequest(url: URL(string: "https://api.music.apple.com/v1/catalog/us/artists/\(artist)/view/latest-release")!))
do {
let response = try await request.response()
let decoded = try JSONDecoder().decode(AlbumReponse.self, from: response.data)
print(decoded)
} catch {
print("error getting latest release: \(error.localizedDescription)")
}
Is this a bug, or am I doing something incorrect? I didn't file a Feedback yet in case this was an error on my end, but if it's a bug I'm happy to put one in. Thanks!
Selecting any option will automatically load the page
Post
Replies
Boosts
Views
Activity
Hello,
I just submitted FB9939377 about this issue, but figured I'd still post on the forums as well.
I have been working on bringing song and album rating functionality to my app, using MusicDataRequest from MusicKit for Swift.
When I like or dislike a song, or delete the existing rating, those changes are reflected immediately in the Music app across all of my devices.
However, when I try to rate or delete an existing rating for an album, the API request is successful, but the changes are not reflected in Music.app on any of my devices. Querying the /v1/me/ratings/albums/[id] endpoint correctly shows the change that was made, but it does not seem to sync the change to any devices, which continue to show whatever the rating state was before the change I made in my app.
I ran 3 tests on albums with the following IDs:
1485040020 - Disliked -> Loved
Disliked in Music.app
/v1/me/ratings/albums/1485040020 shows the value of the rating attribute as “-1”
Changed to “Loved” in my app
/v1/me/ratings/albums/1485040020 confirms the value of the rating attribute has changed from “-1” to “1”
Music.app on the iPod I used to make the change in my app, as well as another iPhone 11 signed into that Apple ID show the original “Disliked” rating for the album.
1485042017 - Loved -> No Rating
Liked in Music.app
/v1/me/ratings/albums/1485042017 shows the value of the rating attribute as “1”
Deleted the rating from my app
/v1/me/ratings/albums/1485042017 now 404s, indicating there is no rating for this album.
Music.app on the iPod I used to make the change in my app, as well as another iPhone 11 signed into that Apple ID show the original “Loved” rating for the album.
1485037658 - No Rating -> Loved
Confirmed /v1/me/ratings/albums/1485037658 returns a 404, as there is no rating for this album
“Loved” the album in my app
/v1/me/ratings/albums/1485037658 now returns a value of “1”
Music.app on the iPod I used to make the change in my app, as well as another iPhone 11 signed into that Apple ID show me the option to either “Love” or “Suggest Less Like This,” indicating there is no existing rating for the album.
There are sysdiagnoses attached to the feedback. Please let me know here or in the Feedback if there is any more information I can provide. Thanks!
(P.S., I'm requiring iOS 15 for the next version of my app, so I've finally been digging into MusicKit. What a well-designed and useful API! It's been so quick and easy to replace most of my existing URLSession data task code with MusicKit, and MusicDataRequest is such a thoughtful inclusion to be able to interface with the elements of the API not natively in MusicKit, with the added benefit of not needing to deal with tokens anymore. Thanks to the team for all of their continued hard work on it.)
Hello,
I have an app that uses the MediaPlayer framework (applicationQueuePlayer specifically) and since the introduction of iOS 14.6 and Lossless audio, some users have been reporting that sometimes they cannot play a song past 15 seconds without playback either pausing or the app making a screeching noise. As far as I knew, this was supposed to be fixed in 14.7, but users running 14.7.1 are reporting it to me whether Lossless is on or off. The problem seems to be intermittent -- there for one user one day and gone the next, though sometimes it sticks around. I am pretty much never able to reproduce it for myself.
My code to load and play the player is pretty simple and has not changed since well before this issue started cropping up. I run setQueue and set the queue with either a descriptor of storeIDs for Apple Music Items or an MPMediaItemCollection for library items, then call Play.
Is there anything I can do about this issue? Are you guys still working on this server side? I need to continue supporting users on older OSes so I am not yet able to use the new MusicKit for Swift player. I don't know if it's fixed there or not.
Thanks! (Tagging in @JoeKun)
As the title asks, is it possible to support SharePlay using the applicationQueuePlayer in the Media Player framework? It seems not to be possible since there is no AVPlaybackCoordinator available like there is for AVPlayer.
Is that correct? It would be nice to be able to support this in my application if possible. Thanks!
My app uses the Media Player framework to play music and has the Audio background mode. When a user pauses the music and backgrounds the app (or if the app is already in the background when they pause), the system does not kill the app as long as it has the active AVAudioSession. This means that as long as a user doesn't start playback from another audio app, mine is available in Control Center for a quick resume.
I recently implemented the UIBackgroundTask API (specifically UIApplication.shared.beginBackgroundTask/endBackgroundTask) to run a 5-20 second server communication task when the app is paused while in the background. Now, iOS kills my app at the conclusion of that task, despite it still having the active audio session. It is no longer in Control Center, and needs to be launched fresh.
Is there anything I can do to prevent the system from killing my app at the conclusion of the background task? I'm starting to get complaints from users that they're having to relaunch the app after every time they pause for more than a few seconds.
Thanks!