title: using AVPlayer to play a time lapse within a UIView
body: <p>I am using a custom image/video picker to pick a time lapse, once the picker view has been dismissed I want to play the time lapse within a UIView that I have put on to the view controller in interface builder. This code I have currently is below but the problem is that at the moment when a time lapse is selected it is not played.</p>
  
  <p><strong>View outlet and var's for video player</strong></p>
  
  <pre><code>@IBOutlet var videoView: UIView!
  let ipc = QBImagePickerController()
  var playerItem: AVPlayerItem?
  var videoPlayer: AVPlayer?
  var playerLayer: AVPlayerLayer?
  </code></pre>
  
  <p><strong>did finish picking assets code</strong></p>
  
  <pre><code>func qb_imagePickerController(imagePickerController: QBImagePickerController, didFinishPickingAssets assets: [AnyObject]) {
      for asset in assets as! [PHAsset] {
          PHImageManager.defaultManager().requestAVAssetForVideo(asset, options: nil, resultHandler: {(avAsset: AVAsset?, audioMix: AVAudioMix?, info: [NSObject : AnyObject]?) -&gt; Void in
              self.playerItem = AVPlayerItem(asset: avAsset!)
              self.videoPlayer = AVPlayer(playerItem: self.playerItem!)
              self.playerLayer = AVPlayerLayer(player: self.videoPlayer)
              self.playerLayer!.frame = self.videoView.bounds
          })
      }
      self.dismissViewControllerAnimated(true, completion: { self.play() })
  }
  </code></pre>
  
  <p><strong>play() function code</strong></p>
  
  <pre><code>func play(){
  
      videoPlayer!.play()
  }
  </code></pre>
  
  <p><strong>unexpectedly found nil when unwrapping an optional value</strong>
  <a href="https://i.stack.imgur.com/Fsg72.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Fsg72.png" alt="enter image description here"></a></p>