I'm doing a test program dealing with audio and tableView, right now I have the controller working and playing the chosen song correctly, but I'm trying to display the metadata from the mp3 file and is not doing anything currently I have it like this:
Function to print the data:
func testAudioStuff(testURL testURL: NSURL) {
let audioInfo = AVPlayerItem(URL: testURL)
let metaDataList = audioInfo.asset.metadata as [AVMetadataItem]
for item in metaDataList {
if item.commonKey == nil { continue }
if let key = item.commonKey, let value = item.value {
print(key)
print(value as! String)
if key == "title" {
print(key)
print("here is the title" + (value as! String))
}
if key == "artist" {
print(key)
print("here is the artist" + (value as! String))
}
if key == "artwork" {
print("here is the artwork" + (value as! String))
}
}
}
}
Function to play the music:
func playSelectedMusic(song: Int, section: Int) {
if section == 1 {
if let starMusic = productsAndMusic["Music"] {
let play = starMusic[song].componentsSeparatedByString(".")[0]
if let fileToPlay = NSBundle.mainBundle().pathForResource(play, ofType: "mp3") {
/ testAudioStuff(testURL: NSURL(string: fileToPlay)!)
do {
player = try AVAudioPlayer(contentsOfURL: NSURL(string: fileToPlay)!)
} catch Errors.GeneralError { }
catch let error as NSError { p
rint("i dunno this does not comes with instructions \(error)")
} catch let something as ErrorType {
print("somehting else \(something)")
}
player.prepareToPlay()
player.play()
}
}
} else {
}
}
As I mentioned it plays the selected song in the simulator but it does not print the metadata, why?, any help? Is in Xcode 7 beta 2.