title: How to obtain audio metadata from music library mediaPicker and the Files app documentPicker?
body: <p>In Swift 4, I can't figure out how to obtain audio metadata from the document picker when importing audio files and from the media picker when picking a media item from the user's media library. I am currently converting the url from both import methods to an <code>AVAudioPlayer</code> item. Can someone please let me know a method, even if I have to code it separately for both the <code>mediaPicker</code> and the <code>documentPicker</code>?</p>
  
  <pre><code>func mediaPicker(_ mediaPicker: MPMediaPickerController, didPickMediaItems mediaItemCollection: MPMediaItemCollection) {
  
      for song in mediaItemCollection.items as [MPMediaItem] {
  
          // AVAudioPlayer
          let url = song.value(forProperty: MPMediaItemPropertyAssetURL) as? NSURL
  
          audioPlayer = try? AVAudioPlayer(contentsOf: url! as URL)
          audioPlayer.prepareToPlay()
          audioPlayer.play()
      }
  
      mediaPicker.dismiss(animated: true, completion: nil)
  }
  
  
      func documentPicker(_ controller: UIDocumentPickerViewController, didPickDocumentAt url: URL) {
      guard controller.documentPickerMode == .import else { return }
  
      let fileURL = url
  
      let url = url.deletingPathExtension()
  
      audioPlayer = try? AVAudioPlayer(contentsOf: fileURL)
      audioPlayer.enableRate = true
      audioPlayer.prepareToPlay()
      audioPlayer.play()
      updateCurrentTrack()
  }
  </code></pre>