Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Showing a lock screen image using MPNowPlayingInfoCenter doesn't work

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.

like image 301
Joel HJ Avatar asked Dec 29 '25 05:12

Joel HJ


1 Answers

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

like image 196
Joel HJ Avatar answered Dec 31 '25 19:12

Joel HJ



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!