                 if let status = change?[NSKeyValueChangeKey.newKey] as? NSNumber {
                     switch (status.intValue as AVPlayerStatus.RawValue) {
                     case AVPlayerStatus.readyToPlay.rawValue:
-                        self._playerView.playerLayer.player = self._avplayer
-                        self._playerView.playerLayer.isHidden = false
+                        if let layer = self._playerView.playerLayer {
+                            layer.player = self._avplayer
+                            layer.isHidden = false
+                        }
                     case AVPlayerStatus.failed.rawValue:
                         self.playbackState = PlaybackState.failed
                     default:

    open override func loadView() {
        self._playerView = PlayerView(frame: CGRect.zero)
        self._playerView.fillMode = AVLayerVideoGravityResizeAspect
        self._playerView.playerLayer.isHidden = true
        self.view = self._playerView
    }
    


internal class PlayerView: UIView {

    override class var layerClass: Swift.AnyClass {
        get {
            return AVPlayerLayer.self
        }
    }

    var playerLayer: AVPlayerLayer? {
        get {
            return self.layer as? AVPlayerLayer
        }
    }

    var player: AVPlayer? {
        get {
            return self.playerLayer?.player
        }
        set {
            if self.playerLayer?.player != newValue {
                self.playerLayer?.player = newValue
            }
        }
    }

    var fillMode: String {
        get {
            return self.playerLayer?.videoGravity ?? ""
        }
        set {
            self.playerLayer?.videoGravity = newValue
        }
    }
    
    // MARK: - object lifecycle

    override init(frame: CGRect) {
        super.init(frame: frame)
        self.playerLayer?.backgroundColor = UIColor.black.cgColor
    }

    required init?(coder aDecoder: NSCoder) {
        super.init(coder: aDecoder)
        self.playerLayer?.backgroundColor = UIColor.black.cgColor
    }

}
