0

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!)
            }

        }
    }
}
Binh Bui
  • 343
  • 1
  • 8
  • try this http://stackoverflow.com/a/30244852/2303865 – Leo Dabus Apr 26 '16 at 21:38
  • I tried but I want to know if the song's title or artist exists and that one doesn't help, it will just skip over because the metadata for that doesn't exist – Binh Bui Apr 26 '16 at 21:49
  • `var hasTitle = false; for item in metadataList { if item.commonKey != nil && item.value != nil && item.commonKey == "title" { hasTitle = true } }` – Leo Dabus Apr 27 '16 at 02:17

0 Answers0