3

I have the following code and is working for me but it can only currently show artist and song :

let mpic = MPNowPlayingInfoCenter.defaultCenter()

mpic.nowPlayingInfo = [MPMediaItemPropertyTitle:songs[currentAudioIndex].songName,
                        MPMediaItemPropertyArtist:songs[currentAudioIndex].artistName]

I tried also setting the picture with the following code but it isn't working :

mpic.nowPlayingInfo = [MPMediaItemPropertyTitle:songs[currentAudioIndex].songName,
                    MPMediaItemPropertyArtist:songs[currentAudioIndex].artistName,
                    MPMediaItemPropertyArtwork:songs[currentAudioIndex].songImage]

SongImage is of type UIImage.

Joel HJ
  • 181
  • 1
  • 5
  • What do you mean by doesn't work ? Any exceptions, error messages ? –  Jan 17 '15 at 16:30

2 Answers2

13

Never mind I figured out.

If anyone want to learn you have to do the following

    let mpic = MPNowPlayingInfoCenter.defaultCenter()

// initialize an instance of MPMediaItemArtWork with a UIImage

    var albumArtWork = MPMediaItemArtwork(image: songs[currentAudioIndex].songImage)

// Then assign it to the MPNowPlayingInfoCenter

    mpic.nowPlayingInfo = [
        MPMediaItemPropertyTitle:songs[currentAudioIndex].songName,
        MPMediaItemPropertyArtist:songs[currentAudioIndex].artistName,
        MPMediaItemPropertyArtwork:albumArtWork

    ]

Hope this helps anyone who is also struggling with this.

Thanks

Joel HJ
  • 181
  • 1
  • 5
  • 1
    Correct. I was just going to tell you this! Good research. Notice how posting causes you to figure it out for yourself. Next time, save bandwidth and use the "rubber duck". :) – matt Jan 17 '15 at 17:04
-1
                MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = [MPMediaItemPropertyArtist : AudioCenter.sharedInstnce.currentReciter().name,
                                                                     MPMediaItemPropertyTitle : AudioCenter.sharedInstnce.currentSurah()!.name,
                                                                     MPMediaItemPropertyArtwork:MPMediaItemArtwork(image: UIImage(named: "Logo")!)]
Atef
  • 2,872
  • 1
  • 36
  • 32