title: Displaying Artwork for .MP3 file
body: <p>I am trying to currently display the album artwork for a locally stored .MP3 track in an ImageView. Does anyone know how to fetch this artwork in Swift in order to accomplish this? </p>
  
  <p>I have found this solution (<a href="https://stackoverflow.com/questions/14030746/ios-avfoundation-how-do-i-fetch-artwork-from-an-mp3-file">iOS AVFoundation: How do I fetch artwork from an mp3 file?</a>) but the code is written in Objective C. I simply want to grab the image embedded in my MP3 and display it in my ImageView. </p>
  
  <p>I've looked at the API documentation for the MPMediaItemArtwork and found an example that also accomplishes what I am trying to accomplish in Objective C as well here(<a href="http://www.codeitive.com/0zHjkUjUWX/not-able-to-get-the-uiimage-from-mpmediaitempropertyartwork.html" rel="noreferrer">http://www.codeitive.com/0zHjkUjUWX/not-able-to-get-the-uiimage-from-mpmediaitempropertyartwork.html</a>) but cannot come up with a solution. My code is as follows:</p>
  
  <pre><code>import UIKit
  import AVFoundation
  import MediaPlayer
  
  class ViewController: UIViewController {
  let audioPath:NSURL! = NSBundle.mainBundle().URLForResource("SippinOnFire", withExtension: "mp3")
  
  @IBOutlet var artistImage: UIImageView!
  @IBOutlet var trackLabel: UILabel!
  @IBOutlet var artistLabel: UILabel!
  @IBOutlet var sliderValue: UISlider!
  var player:AVAudioPlayer = AVAudioPlayer()
  
  
  @IBAction func play(sender: AnyObject) {
  
  
      let audioInfo = MPNowPlayingInfoCenter.defaultCenter()
  println(audioInfo)
  
  
      player.play()
      //println("Playing \(audioPath)")
  
  
      let playerItem = AVPlayerItem(URL: audioPath)
      let metadataList = playerItem.asset.metadata as! [AVMetadataItem]
  
  
      for item in metadataList {
          if let stringValue = item.value {
             println(item.commonKey)
              if item.commonKey == "title" {
                  trackLabel.text = stringValue as? String
              }
              if item.commonKey  == "artist" {
                  artistLabel.text = stringValue as? String
              }
              if item.commonKey  == "artwork" {
                  if let audioImage = UIImage(data: item.value as! NSData) {
                      let audioArtwork = MPMediaItemArtwork(image: audioImage)
                      println(audioImage.description)
                  }
             }
  
  
          }
      }
  }
  @IBAction func pause(sender: AnyObject) {
  
      player.pause()
  }
  @IBAction func stop(sender: AnyObject) {
  
      player.stop()
      player.currentTime = 0;
  }
  @IBAction func sliderChanged(sender: AnyObject) {
  
      player.volume = sliderValue.value
  
  }
  
  override func viewDidLoad() {
      super.viewDidLoad()
  
               var error:NSError? = nil
  
      player = AVAudioPlayer(contentsOfURL: audioPath!, error: &amp;error)
  
      player.volume = 0.5;
  
  }
  
  override func didReceiveMemoryWarning() {
      super.didReceiveMemoryWarning()
      // Dispose of any resources that can be recreated.
  }
  
  
  }
  </code></pre>
  
  <p>Here is a screen shot of my sample .mp3 file. As you can see there is indeed album artwork that is both visible in the "get info" section of Finder. I've also opened the .mp3 in my iTunes to make sure and have confirmed there is artwork in the "get info" section of it there as well as under the "artwork" tab.</p>
  
  <p>However, when trying to use the commonKey to assign the image to my imageView I find that there is no commonKey for "artwork".</p>
  
  <p><img src="https://i.stack.imgur.com/IeITD.png" alt="sample MP3 data"></p>
  
  <p>Thanks</p>