title: Playing a video file from a url in Swift 4/Xcode 9: AVF context unavailable for sharedAudioPresentationContext
body: <p>I am trying to implement an AVPlayer which loads and plays a video from a url. This is placed within a function that is called by a button. Here is my current code:</p>
  
  <pre><code>import UIKit
  import AVKit
  import AVFoundation
  
  class MovieDetailViewController: UIViewController {
  
      override func viewDidLoad() {
          super.viewDidLoad()
      }
  
      @IBAction func playTrailer(_ sender: Any) {
          guard let videoURL = URL(string: "http://caribbeancinemas.com/img/trailers/6134.mp4") else {
              return
          }
  
          let player = AVPlayer(url: videoURL)
          let controller = AVPlayerViewController()
          controller.player = player
  
          present(controller, animated: true) {
              player.play()
          }
      }
  }
  </code></pre>
  
  <p>When I run the app on the simulator the video actually plays but there are two issues happening:</p>
  
  <ol>
  <li><p>I get the following error message in the console:</p>
  
  <blockquote>
    <p>2018-03-31 16:49:53.389148-0400 MoviesApp[18928:3137301] [MediaRemote] [AVOutputContext] WARNING: AVF context unavailable for sharedAudioPresentationContext
    2018-03-31 16:49:53.497987-0400 MoviesApp[18928:3137301] [framework] CUICatalog: Invalid asset name supplied: '(null)'
    2018-03-31 16:49:53.498937-0400 MoviesApp[18928:3137301] [framework] CUICatalog: Invalid asset name supplied: '(null)'
    2018-03-31 16:49:53.857871-0400 MoviesApp[18928:3138058] Task &lt;223C4724-B3B5-4EBE-9AE0-5BA3C30B37C6>.&lt;2> finished with error - code: -999
    2018-03-31 16:49:55.365686-0400 MoviesApp[18928:3138196] Task &lt;95E91605-9B52-4212-97B3-47E73CE21B8B>.&lt;1> finished with error - code: -999</p>
  </blockquote></li>
  <li><p>The video player doesn't starts playing the video right away (buffering) but it seems to wait until it downloads the entire video before playing.</p></li>
  </ol>
  
  <p>I have looked here for a solution to this but haven't found one yet so any help is appreciated.</p>
  
  <p>Thanks in advance!</p>