             })
         }
     }
-    private var playerLayer: AVPlayerLayer?
-    private var playerItem: AVPlayerItem? = nil {
-        willSet {
-            // Remove any previous KVO observer.
-            guard let playerItemStatusObserver = playerItemStatusObserver else { return }
-            playerItemStatusObserver.invalidate()
-        }
-        didSet {
-            player?.replaceCurrentItem(with: playerItem)
-            playerItemStatusObserver = playerItem?.observe(\AVPlayerItem.status, options: [.new, .initial], changeHandler: { [weak self] (item, _) in
-                guard let strongSelf = self else { return }
-                if item.status == .failed {
-                    strongSelf.activityIndicator.stopAnimating()
-                    if let item = strongSelf.player?.currentItem, let error = item.error, let url = item.asset as? AVURLAsset {
-                        strongSelf.playerObserverDelegate?.didFailed(withError: error.localizedDescription, for: url.url)
-                    } else {
-                        strongSelf.playerObserverDelegate?.didFailed(withError: "Unknown error", for: nil)
-                    }
-                }
-            })
-        }
-    }
     var error: Error? {
         return player?.currentItem?.error
     }
-    var activityIndicator: UIActivityIndicatorView
+    var activityIndicator: UIActivityIndicatorView!
+    
+    var currentItem: AVPlayerItem? {
+        return player?.currentItem
+    }
+    var currentTime: Float {
+        return Float(self.player?.currentTime().value ?? 0)
+    }
+    
+    //MARK: - Public Vars
+    public weak var playerObserverDelegate: IGPlayerObserver?
     
     //MARK:- Init methods
     override init(frame: CGRect) {
         activityIndicator = UIActivityIndicatorView(style: .whiteLarge)
+        super.init(frame: frame)
+        setupActivityIndicator()
+    }
+    required init?(coder aDecoder: NSCoder) {
+        activityIndicator = UIActivityIndicatorView(style: .whiteLarge)
+        super.init(coder: aDecoder)
+        setupActivityIndicator()
+    }
+    deinit {
+        if let existingPlayer = player, existingPlayer.observationInfo != nil {
+            removeObservers()
+        }
+        debugPrint("Deinit called")
+    }
+    
+    // MARK: - Internal methods
+    func setupActivityIndicator() {
         activityIndicator.hidesWhenStopped = true
-        super.init(frame: frame)
         //backgroundColor = UIColor.rgb(from: 0xEDF0F1)
         backgroundColor = .black
         activityIndicator.center = CGPoint(x: self.frame.width/2, y: self.frame.height/2)
         self.addSubview(activityIndicator)
-    }
-    required init?(coder aDecoder: NSCoder) {
-        fatalError("init(coder:) has not been implemented")
-    }
-    deinit {
-        if let existingPlayer = player, existingPlayer.observationInfo != nil {
-            removeObservers()
-        }
-        debugPrint("Deinit called")
-    }
-    var currentItem: AVPlayerItem? {
-        return player?.currentItem
-    }
-    var currentTime: Float {
-        return Float(self.player?.currentTime().value ?? 0)
     }
     func removeObservers() {
         cleanUpPlayerPeriodicTimeObserver()

}

protocol PlayerControls: class {
    //This func should play as it is if player.playerItem is NIL, then if there is item(ie.AVPlayerItem) you should replace with current one.
    func play(with resource: VideoResource)
    func play()
    func pause()

    var playerStatus: PlayerStatus { get }
}

class IGPlayerView: UIView {
    
    //MARK: - Private Vars
    private var timeObserverToken: AnyObject?
    private var playerItemStatusObserver: NSKeyValueObservation?
    private var playerTimeControlStatusObserver: NSKeyValueObservation?
    private var playerLayer: AVPlayerLayer?
    private var playerItem: AVPlayerItem? = nil {
        willSet {
            // Remove any previous KVO observer.
            guard let playerItemStatusObserver = playerItemStatusObserver else { return }
            playerItemStatusObserver.invalidate()
        }
        didSet {
            player?.replaceCurrentItem(with: playerItem)
            playerItemStatusObserver = playerItem?.observe(\AVPlayerItem.status, options: [.new, .initial], changeHandler: { [weak self] (item, _) in
                guard let strongSelf = self else { return }
                if item.status == .failed {
                    strongSelf.activityIndicator.stopAnimating()
                    if let item = strongSelf.player?.currentItem, let error = item.error, let url = item.asset as? AVURLAsset {
                        strongSelf.playerObserverDelegate?.didFailed(withError: error.localizedDescription, for: url.url)
                    } else {
                        strongSelf.playerObserverDelegate?.didFailed(withError: "Unknown error", for: nil)
                    }
                }
            })
        }
    }
    
    //MARK: - iVars
    var player: AVPlayer? {
        willSet {
            // Remove any previous KVO observer.
