     
     func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
         tableView .deselectRow(at: indexPath, animated: true)
-        let video = videos[indexPath.row]
-        videoPlayer.playWithURL(URL(string: video.sourceURL!)!, title: video.title!)
+        guard let video = videos[indexPath.row] else {
+            return
+        }
+        videoPlayerPlayVideo(video: video)
     }
 }


    @IBOutlet var tableView: UITableView!
    @IBOutlet var videoPlayer: SHVideoPlayer!
    fileprivate var videos: [SHVideo] = VideoDataSource.getModel()
    
    override func viewDidLoad() {
        super.viewDidLoad()

    
    override func viewDidAppear(_ animated: Bool) {
        super.viewDidAppear(animated)
        guard let video = videos[1] else {
            return
        }
        videoPlayerPlayVideo(video: video)
    }
    
    fileprivate func videoPlayerPlayVideo(video: SHVideo) {
        guard let sourceURL = video.sourceURL else {
            return
        }
        
        guard let url =  URL(string: sourceURL),
            let title = video.title else {
                return
        }
        videoPlayer.playWithURL(url, title: title)
    }
}

