0

I checked some of SO answers but it doesn't work for me!

I need to get lyrics for the current playing song.

I get an empty result if I simply try to get lyrics from a media item:

   if var music = mediaItemCollection.items as? [MPMediaItem]{
            music = Array(Set(music))
            for (_, music) in music.enumerated(){
                
                let songInfo: SongInfo = SongInfo(
                    albumTitle: music.albumTitle ?? "",
                    artistName: music.artist ?? "",
                    songTitle: music.title ?? "",
                    songId: Int(music.persistentID),
                    assetURL: music.assetURL!
                    
                )
                print(music.lyrics)
                songArr.append(songInfo)
            }
      }

I've tried to get lyrics through asset URL as suggested in SO answers, but it does not work.

let songAsset = AVURLAsset(url: music.assetURL!)
if let lyricsFromAsset = songAsset.lyrics {
    print("Lyrics from asset: \(lyricsFromAsset)")
}

Can somebody help with getting lyrics for the current playing song from apple music?

Yogesh Patel
  • 1,893
  • 1
  • 20
  • 55
  • I think: you are using content from Apple Music, while code you found didn't. They expected local music, with all metadata readable at launch. You need an async call, using https://developer.apple.com/documentation/avfoundation/avasynchronouskeyvalueloading might be helpful. – Larme Feb 21 '21 at 11:39
  • Thanks!, I tried with local music too but not getting lyrics. – Yogesh Patel Feb 21 '21 at 14:30

0 Answers0