title: How to pass HTTP Basic Authentication to AVAudioPlayer in Swift 4
body: <p>I'm attempting to load a remote MP3 through the <code>AVAudioPlayer</code> in Swift 4. So far, everything is working just great. </p>
  
  <p>Now, I'm attempting to load our secure URL, which uses Basic Authentication for the URL.</p>
  
  <p>What I have is this:</p>
  
  <pre><code>    let username = "my_username"
      let password = "my_password"
      let loginString = String(format: "%@:%@", username, password)
      let loginData = loginString.data(using: String.Encoding.utf8)!
      let base64LoginString = loginData.base64EncodedString()
  
      // create the request
      let url = URL(string: "https://audio.my_domain.com/\(hashKey)/my_file.mp3")!
      var request = URLRequest(url: url)
      request.httpMethod = "POST"
      request.setValue("Basic \(base64LoginString)", forHTTPHeaderField: "Authorization")
  
      guard let audioPlayer = try? AVAudioPlayer(contentsOf: request) else {
          self.endPlayback()
          return
      }
  </code></pre>
  
  <p>Of course the error that I get is:</p>
  
  <blockquote>
    <p>Cannot convert value of type 'URLRequest' to expected argument type
    'URL'</p>
  </blockquote>
  
  <p>I'm not surprised by this as a <code>URL</code> is not a <code>URLRequest</code> object. So, my question is. How can I load the URL stream into the <code>AVAudioPlayer</code> using Basic HTTP Authentication?</p>
  
  <p>I can't seem to find anywhere that does this. Perhaps this isn't possible?</p>