I am doing a project which I have to create a media player app. I have put my songs in a folder inside Xcode. And I have successfully fetched the metadata of the song.
However, because I put my fetched title and artist to an array, if a song has no artist or title, it will simply skip over and since the 'metadataList' only list the available metadata, I can't check if a song has an artist or not.
let songArray = NSBundle.mainBundle().URLsForResourcesWithExtension("mp3", subdirectory: "song")! as [NSURL]
var songTitleList = [String]()
var songArtistList = [String]()
func getTitleAndArtist() {
for song in songArray{
let playerItem = AVPlayerItem(URL: song)
let metadataList = playerItem.asset.commonMetadata
for item in metadataList {
if item.commonKey == "title" {
songTitleList.append(item.stringValue!)
}
if item.commonKey == "artist" {
songArtistList.append(item.stringValue!)
}
}
}
}