ios - 在 Swift 中获取轨道的元数据

标签 ios swift spotify

我正在做 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/

相关文章:

IOS 核心数据 - 查找或创建重复插入

从 Obj-C 类继承的 Swift 中的 iOS 错误转换对象

ios - 在 Swift iOS 中播放 PCM 文件

javascript - 尝试使用 Spotify 的 API 创建播放列表时出现 "Request failed with status code 401"错误

android - 是否存在适用于 android java 的 libspotify 12 的库?

python - 如何在Python中使用spotDL?

ios - 如何找出两个自定义单元格中的哪一个被选中?

objective-c - 一次性设置所有 UITextField 的样式,而不是在每个 ViewController 中设置样式?

ios - 如何在 UITextView 中显示数组中的文本,我可能只需要正确的字符串格式?

ios - 仅从存在用户 UID 的节点获取特定的子值