Search code examples
iosswiftmpmediaitemmpmediaquerympmediaitemcollection

Get list of albums from ipod library in swift


I want to make a simple media player in Swift. I want to make a table with all Albums on the iphone and after selecting the album i want to play the songs of it. But i can not get the album titles (and artwork).

I tried:

    var query = MPMediaQuery.albumsQuery()
    let mediaCollection = MPMediaItemCollection(items: query.items)
    println(mediaCollection.items)


    let player = MPMusicPlayerController.systemMusicPlayer()
    player.setQueueWithItemCollection(mediaCollection)

    player.play()

Solution

  • MPMediaItem has valueForProperty() function. The properties which you need are MPMediaItemPropertyAlbumTitle and MPMediaItemPropertyArtwork.