In my music player using the new Apple Music API(released May 12, 2016) in iOS 9 (swift, although I'm currently getting familiar with Objective-C as well), I can display information from a streamed song, but not the artwork. I am using MediaPlayer, UIKit, and StoreKit frameworks. I have been successful requesting authorization to AddToCloudMusicLibrary and MusicCatalogPlayback. I have success displaying Apple Music artwork from songs that I downloaded from the Apple Music app, as well as artwork from my personal song collection. I have seen other people with issues on this, with no luck...
Just going to try asking one more time, for the people, before I resort to displaying a default image(which is necessary anyway for error-handling), or pull from an alternate service. Any help would be great! Not really an error in my code so I won't show it, unless requested to help solve this problem.
My first attempt at posting code...Here is what I have in a swift file called Authorization. Do I need to reference this code anywhere or should it be in the AppDelegate file instead? This is the only part of my project I am not 100% sure of.
import StoreKit
import MediaPlayer
import UIKit
class AppleMusicPlayer: NSObject {
let applePlayer = MPMusicPlayerController.systemMusicPlayer()
func playID(productID: String) {
SKCloudServiceController.requestAuthorization { status in
let controller = SKCloudServiceController()
controller.requestCapabilitiesWithCompletionHandler { capabilities, error in
if capabilities != SKCloudServiceCapability.None {
MPMediaLibrary.defaultMediaLibrary().addItemWithProductID(productID) { entities, error in
self.appPlayer.setQueueWithStoreIDs([productID])
self.appPlayer.shuffleMode = .Songs
self.appPlayer.play()
}
}
}
}
}
}
This is a bug in the current API for Apple Music. As you mentioned, songs that are not in the user's library but are instead streamed from AM will not return album artwork.
You should file a feature enhancement at bugreport.apple.com (you can also dupe mine from 6 months ago 25413082 ).
In the meantime your best bet would be to use the iTunes api to retrieve the album artwork, unfortunately this doesn't return the correct results 100% of the time...
The best method I found was to use the get song from catalog Apple Music API request, documented here.
You just need to pass in the song identifier (the one which is used for playback) and the storefront identifier which is being used to play the song. This sould always yield an accurate result, compared to the anwer which uses a search request which might fail.
I struggled with this for quite some time. If this ever was an actual bug I'm not sure about however you can't set a
UIImageView
to thenowPlayingItem
like the way you might expect. You must pull the image from the Apple Music service api. See Documentation here. Also have a look at the sample project here that Apple provides for a full understanding. Also here is a full sample of how I overcame this issue.Inside the MediaItem class there is a property called MPMediaItemPropertyArtwork. You will be able to retrieve the artwork for the album in the following way: