I have the similar problem like:
- How do I get the lyrics of the currently playing song in Swift 4? - there is no answer here
- iPhone song lyrics access - answer does not work
- How to get lyrics for Now Playing song in iOS10 (Swift 3) - answer does not work
I need to get lyrics for current playing song.
I get empty result if I simply try to get lyrics from a media item:
let musicPlayerController = MPMusicPlayerController.systemMusicPlayer
// ...
if let nowPlayingItem = musicPlayerController.nowPlayingItem {
// We have empty string here
if let lyrics = nowPlayingItem.lyrics {
print("Lyrics: \(lyrics)")
}
}
I've tried to get lyrics through asset url as suggested in answers above, but it does not work, asset url is always nil.
let musicPlayerController = MPMusicPlayerController.systemMusicPlayer
// ...
if let nowPlayingItem = musicPlayerController.nowPlayingItem {
if let songUrl = nowPlayingItem.value(forProperty: MPMediaItemPropertyAssetURL) as? URL {
print("song url: \(songUrl)")
let songAsset = AVURLAsset(url: songUrl)
if let lyricsFromAsset = songAsset.lyrics {
print("Lyrics from asset: \(lyricsFromAsset)")
}
}
}
I've also tried without any success (also get nil and empty string accordingly):
print("asset url: \(nowPlayingItem.assetURL)")
print("lyrics from value for property: \(nowPlayingItem.value(forProperty: MPMediaItemPropertyLyrics))")
I know exactly that the song has lyrics because I see it in Apple Music app on iPhone for the song. I've tried to get lyrics for the song: Queen - Bohemian Rhapsody.
Can somebody help with getting lyrics for current playing song from apple music?