Вывод данных о треке в Control Center


#1

Добрый день

Не поможет ли кто-нибудь объяснением как передавать данные о проигрываемом треке на заблокированный экран смартфона и в Control Center? Вот как на скриншоте ниже

Заранее спасибо


Control Center на устройстве
#2

Сделал следующим образом:

В отдельную функцию засунул параметры которые стоит выводить и датчик активности трека

func setInfoCenterCredentials(AirRate: Double) {
        MPNowPlayingInfoCenter.default().nowPlayingInfo = [MPMediaItemPropertyTitle: curSongName,
                                                           MPMediaItemPropertyArtist: curSongArtist,
                                                           MPMediaItemPropertyPlaybackDuration: curSongDuration,
                                                           MPNowPlayingInfoPropertyElapsedPlaybackTime: curSongDuration-curSongTime,
                                                           MPNowPlayingInfoPropertyPlaybackRate: AirRate]
    }

Вот такой код в ViewDidLoad:

//Отображение проигрываемого контента как стрима
        if #available(iOS 10.0, *) {
            MPNowPlayingInfoCenter.default().nowPlayingInfo?[MPNowPlayingInfoPropertyIsLiveStream] = true
        }
        //Кнопка Play/Stop в Command Center
        if #available(iOS 9.1, *) {
            let center = MPRemoteCommandCenter.shared()
            [center.pauseCommand, center.togglePlayPauseCommand, center.nextTrackCommand, center.previousTrackCommand, center.changeRepeatModeCommand, center.changeShuffleModeCommand, center.changePlaybackRateCommand, center.seekBackwardCommand, center.seekForwardCommand, center.skipBackwardCommand, center.skipForwardCommand, center.changePlaybackPositionCommand, center.ratingCommand, center.likeCommand, center.dislikeCommand, center.bookmarkCommand].forEach {
                $0.isEnabled = false
            }
            center.playCommand.addTarget { (commandEvent) -> MPRemoteCommandHandlerStatus in
                self.play(broadcastCell: true)
                return MPRemoteCommandHandlerStatus.success
            }
            center.stopCommand.addTarget { (commandEvent) -> MPRemoteCommandHandlerStatus in
                self.play(broadcastCell: true)
                return MPRemoteCommandHandlerStatus.success
            }
        }
        
        UIApplication.shared.beginReceivingRemoteControlEvents()

Ну и переключалку активности трека по такому шаблону:

setInfoCenterCredentials(AirRate: 0.0)