1

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.

Ryohei
  • 713
  • 2
  • 9
  • 20
  • Not exactly same as you have, but this will help you: https://stackoverflow.com/questions/49443493/swift-how-can-i-convert-saved-audio-file-conversations-to-text/49443781#49443781 – Sagar Chauhan Sep 16 '19 at 13:18
  • Thanks for the tip but can you with a bit more detail tell me how STT/TTS would help this? It at first sight looks irrelevant to MPMediaItem tho? @SagarChauhan – Ryohei Sep 16 '19 at 14:51
  • OH I understood you but as I edited above, I cannot even access assetURL which returns nil. Is there any way perhaps? – Ryohei Sep 16 '19 at 15:33
  • did you get any solution to this? – Yogesh Patel Feb 21 '21 at 09:11
  • @YogeshPatel sadly no. It seems that Apple does not allow to do this so I gave up. – Ryohei Apr 05 '21 at 04:12
  • No, I saw some of the apps that have this functionality. I think apple not rejecting this. Once I'll live the app. I'll let you know the status. – Yogesh Patel Apr 05 '21 at 04:35

0 Answers0