Swift: Remote Command Center not show in lockScreen

孤街浪徒 提交于 2020-01-16 18:24:12

问题


Iam trying to show command center in lock screen and not woking for me, i see the code from this tutorial, and write the same code but also not working https://github.com/lukagabric/LGAudioPlayerLockScreen

this is the code

  var nowPlayingInfo = [MPMediaItemPropertyTitle: currentPlaybackItem.trackName,
                          MPMediaItemPropertyAlbumTitle: currentPlaybackItem.albumName,
                          MPMediaItemPropertyArtist: currentPlaybackItem.artistName,
                          MPMediaItemPropertyPlaybackDuration: audioPlayer.duration,
                          MPNowPlayingInfoPropertyPlaybackRate: NSNumber(value: 1.0 as Float)] as [String : Any]

    if let image = UIImage(named: currentPlaybackItem.albumImageName) {
        nowPlayingInfo[MPMediaItemPropertyArtwork] = MPMediaItemArtwork(image: image)
    }
    self.nowPlayingInfoCenter.nowPlayingInfo = nowPlayingInfo

Any one can help


回答1:


I noticed when trying to update now playing info dictionary you have to fill key with data even empty string.

are you sure trackName, albumName, artistName are not nil ?

ModernAVPlayer has a good example: check this "NowPlaying" code




回答2:


Thanks all, I found the solution, my last code in set category

self.audioSession.setCategory(AVAudioSession.Category.playback , mode: .default , options: .mixWithOthers )

and the solution is

self.audioSession.setCategory(AVAudioSession.Category.playback , mode: .default , options: .init(rawValue: 0) )


来源:https://stackoverflow.com/questions/53986069/swift-remote-command-center-not-show-in-lockscreen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!