For past few hours, I researched how to fetch lyrics from songs in my Apple Music library reading other posts here, but in my environment it was not successful. And then I thought that maybe this is because of Apple Music Membership. I assumed that a user with subscription (not purchase songs) is not allowed to access any songs from library or something.
Swift 4.0 iOS 12.2
As other posts say, I implemented MediaPlayer
I made an instance of MPMediaPickerController and set its delegate, showsCloudItems = false.
After a song was picked, I did this.
func mediaPicker(_ mediaPicker: MPMediaPickerController, didPickMediaItems mediaItemCollection: MPMediaItemCollection) {
player.setQueue(with: mediaItemCollection)
player.play()
let song = player.nowPlayingItem
print(song?.assetURL) // returns nil
print(song?.artist) // returns string
print(song?.hasProtectedAsset) // true or false
if let songUrl = song?.value(forProperty: MPMediaItemPropertyLyrics) as? String {
print(songUrl.isEmpty ? "null" : songUrl)
// let songAsset = AVURLAsset(url: songUrl, options: nil)
// let lyricsText = songAsset.lyrics
// print(lyricsText)
}
dismiss(animated: true, completion: nil)
}
As you can see it there (commented out), I aslo tried MPMediaItemPropertyAsset, but it returns nil. No lyrics was returned. Even assetURL returns nil.
By the way, I implemented this line below to filter not protected assets, but nothing appeared so I deleted.
picker.showsItemsWithProtectedAssets = false
I want lyrics to be fetched. But not successful. There is code that seems to make it possible, so I wanted some clear reason why this fails. Is it because of like DRM related law, or just some bug in iOS 12? Thank you.