title: Save Firebase Storage Video and Play with AVPlayerViewController
body: <p>Building an app that allows users to upload media to Firebase Storage. Upload seems to be working fine, however I can't get video downloads to play.</p>
  
  <p>I saved a file to the app to test the AVPlayer and it works perfect.</p>
  
  <pre><code>func handleGesture() {
      print("handle gesture")
      if detailMediaType == "Video"{
          performSegueWithIdentifier("toVideoView", sender: self)
          print("video segue called")
      }
  } 
  
  override func prepareForSegue(segue: UIStoryboardSegue, sender: AnyObject?) {
  
      if(segue.identifier == "toVideoView"){
  
          let path = NSBundle.mainBundle().pathForResource("Apartment Ceiling Collapse- Queens, NY", ofType: "mp4")
          var movieUrl = NSURL(fileURLWithPath: path!)
          let filename = getDocumentsDirectory().stringByAppendingPathComponent("movie")
          let videoData = NSData(contentsOfURL: movieUrl)
          videoData!.writeToFile(filename, atomically: true)
  
          self.avPlayer = AVPlayer(URL: movieUrl)
          self.avPlayerViewController.player = self.avPlayer
  
          self.presentViewController(self.avPlayerViewController, animated: false) { () -&gt; Void in self.avPlayerViewController.player?.play()
  
          }
      }
  }
  </code></pre>
  
  <p>Edit: I am now trying to download using downloadURLWithCompletion</p>
  
  <pre><code>FIRStorage.storage().referenceForURL(detailFullsizeUrl).downloadURLWithCompletion { (URL, error) -&gt; Void in
              if (error != nil)
              {
                  print(error!)
              }
              else
              {
  
                  self.firebaseUrl = URL!
  
                  print("firebaseUrl")
                  print(self.firebaseUrl)
                  self.avPlayer = AVPlayer(URL: self.firebaseUrl)
                  self.avPlayerViewController.player = self.avPlayer 
              }
          }
  </code></pre>
  
  <p>I get an AVPlayerViewController with a black screen. When I access the "firebaseUrl" from the web, it downloads a text file that looks like gibberish. </p>
  
  <p><strong>Solution:</strong> 
  Changed up my approach. No longer saving to device. Instead I grabbed the "downloadUrl" metadata from the Firebase Storage object and pass it directly to the AVPlayerViewController.</p>
  
  <pre><code>let avPlayerViewController = AVPlayerViewController()
  var avPlayer:AVPlayer? = nil
  
  override func viewDidLoad() {
      super.viewDidLoad()
        FIRStorage.storage().referenceForURL(detailFullsizeUrl).metadataWithCompletion { (metadata, error) in
          if error != nil{
              print("error getting metadata")
          } else {
              let downloadUrl = metadata?.downloadURL()
              print(downloadUrl)
  
              if downloadUrl != nil{
                  self.avPlayer = AVPlayer(URL: downloadUrl!)
                  self.avPlayerViewController.player = self.avPlayer
                  print("downloadUrl obtained and set")
              }
          }
      }   
  }
  
  func handleGesture() {
      print("handle gesture")
      self.presentViewController(self.avPlayerViewController, animated: true) { () -&gt; Void in
          self.avPlayerViewController.player?.play()
      }
  }
  </code></pre>