【发布时间】:2017-07-25 13:52:13
【问题描述】:
访问MPMusicPlayerController.systemMusicPlayer()(下面的代码)可用于获取 Apple Music 应用程序中正在播放的曲目信息,但有没有一种方法可以访问 Spotify 应用程序中当前正在播放的歌曲的信息?
此答案I need to know how to get information about which player is currently streaming (player, spotify, napster...) 中发布的此代码使用MPNowPlayingInfoCenter,无论使用Apple Music 还是Spotify 等,都为零。
let player = MPMusicPlayerController.systemMusicPlayer()
@IBAction func getMusicButton(_ sender: UIButton) {
if let mediaItem = player.nowPlayingItem {
let title: String = mediaItem.value(forProperty: MPMediaItemPropertyTitle) as! String
let albumTitle: String = mediaItem.value(forProperty: MPMediaItemPropertyAlbumTitle) as! String
let artist: String = mediaItem.value(forProperty: MPMediaItemPropertyArtist) as! String
print("\(title) on \(albumTitle) by \(artist)")
}
}
【问题讨论】:
-
不,此代码不会返回 Apple Music 或 Spotify 的信息,请参阅我上面的编辑
-
您找到解决方案了吗?
-
我没有@KyleGoslan,我的理解是这是一个沙盒问题,而我们无法检测到仅通过 Apple Music 播放的 Spotify(第 3 方应用程序)正在播放的内容。