使用MPNowPlayingInfoCenter显示锁定屏幕图像不起作用

时间:2015-01-17 16:25:51

标签: swift mpnowplayinginfocenter

我有以下代码并且正在为我工​​作,但它目前只能显示艺术家和歌曲:

let mpic = MPNowPlayingInfoCenter.defaultCenter()

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

我尝试使用以下代码设置图片,但它不起作用:

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

SongImage的类型为UIImage。

2 个答案:

答案 0 :(得分:13)

没关系,我想通了。

如果有人想要了解你必须这样做 执行以下操作

    let mpic = MPNowPlayingInfoCenter.defaultCenter()

//使用UIImage

初始化MPMediaItemArtWork的实例
    var albumArtWork = MPMediaItemArtwork(image: songs[currentAudioIndex].songImage)

//然后将其分配给MPNowPlayingInfoCenter

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

    ]

希望这可以帮助那些也在努力解决这个问题的人。

由于

答案 1 :(得分:-1)

                MPNowPlayingInfoCenter.defaultCenter().nowPlayingInfo = [MPMediaItemPropertyArtist : AudioCenter.sharedInstnce.currentReciter().name,
                                                                     MPMediaItemPropertyTitle : AudioCenter.sharedInstnce.currentSurah()!.name,
                                                                     MPMediaItemPropertyArtwork:MPMediaItemArtwork(image: UIImage(named: "Logo")!)]
相关问题