我正在做 Xcode-Swift-Spotify 项目,我唯一想要的就是获取有关当前正在播放的歌曲的信息,信息我的意思是名称、专辑等等,我已经尝试了很多不同的方式,但我无法得到它。请帮我。下面有一个例子
func audioStreaming(audioStreaming: SPTAudioStreamingController!, didStartPlayingTrack trackUri: NSURL!)
{
SPTTrack.trackWithURI(self.player?.currentTrackURI, session: spotifyAuthenticator.session) { (error:NSError!, track:AnyObject!) -> Void in
print(track.name)
}}
我忘了说,我正在使用 Spotify SDK
最佳答案
我给你看我的例子
var avpItem = AVPlayerItem(URL: megaURL)
var commonMetaData = avpItem.asset.commonMetadata as! [AVMetadataItem]
for item in commonMetaData {
if item.commonKey == "title" {
songTitle = item.stringValue
}
if item.commonKey == "artist" {
songArtist = item.stringValue
}
if item.commonKey == "album" {
songAlbum = item.stringValue
}
if item.commonKey == "artwork" {
songArtworkData = item.dataValue
}
元数据的关键字
let AVMetadataCommonKeyTitle: String
let AVMetadataCommonKeyCreator: String
let AVMetadataCommonKeySubject: String
let AVMetadataCommonKeyDescription: String
let AVMetadataCommonKeyPublisher: String
let AVMetadataCommonKeyContributor: String
let AVMetadataCommonKeyCreationDate: String
let AVMetadataCommonKeyLastModifiedDate: String
let AVMetadataCommonKeyType: String
let AVMetadataCommonKeyFormat: String
let AVMetadataCommonKeyIdentifier: String
let AVMetadataCommonKeySource: String
let AVMetadataCommonKeyLanguage: String
let AVMetadataCommonKeyRelation: String
let AVMetadataCommonKeyLocation: String
let AVMetadataCommonKeyCopyrights: String
let AVMetadataCommonKeyAlbumName: String
let AVMetadataCommonKeyAuthor: String
let AVMetadataCommonKeyArtist: String
let AVMetadataCommonKeyArtwork: String
let AVMetadataCommonKeyMake: String
let AVMetadataCommonKeyModel: String
let AVMetadataCommonKeySoftware: String
关于ios - 在 Swift 中获取轨道的元数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32509856/