2

I'm able to access the music that is downloaded on my iPhone THAT I PURCHASED before Apple Music existed. However, I can't seem to find the URLs of the songs that I've downloaded through Apple Music. Does anybody know anything about Apple Music when it comes to accessing the files?

Here is my code for accessing my music:

override func viewDidLoad() {

    let query = MPMediaQuery.songsQuery()
    for song in query.items! {
        if let _ = song.valueForProperty(MPMediaItemPropertyAssetURL) as? NSURL {
            songsArray.append(song)
            songTitles.append(song.title!)
            songArtists.append(song.artist!)
        }            
    }
}
swiftyboi
  • 2,965
  • 4
  • 25
  • 52
  • As said in post http://stackoverflow.com/questions/31364485/apple-music-offline-files-have-no-url files seems to be DRM protected and you are getting a nil MPMediaItemPropertyAssetURL – StephBel May 04 '16 at 09:03

1 Answers1

1

To go ahead and play the songs, here is what you need...

MPMusicPlayerController.systemMusicPlayer().setQueueWithQuery(MPMediaQuery.songsQuery())

and don't forget to play it :)

MPMusicPlayerController.systemMusicPlayer().play()

This is assuming you've done all the necessary requirements for requesting access and such. Let me know if you need any other help. I'm just jumping back into this framework, so I would be more than happy to help.

Jake Dobson
  • 1,716
  • 3
  • 11
  • 29