             DispatchQueue.main.async {
                 UIApplication.shared.endIgnoringInteractionEvents()
                 
-                let player = AVPlayer(url: url)
+                let item = PlayerItemWithUserInfo(url: url)
+                let player = AVPlayer(playerItem: item)
                 let interval = CMTime(seconds: 10, preferredTimescale: CMTimeScale(NSEC_PER_SEC))
                 player.addPeriodicTimeObserver(forInterval: interval, queue: DispatchQueue.main, using: { (time: CMTime) in
                     SetBookmarkService.postBookmark(item: media, time: Int(time.seconds))

                let vc = AVPlayerViewController()
                vc.player = player

                presenter.present(vc, animated: true, completion: { [weak vc] in
                    vc?.player?.play()
                })

        })
    }
}

// A player item that will retain something extra for us.
class PlayerItemWithUserInfo: AVPlayerItem {
    var userInfo: Any?
}

// This class just listens for the 'AVPlayerItemDidPlayToEndTime' and takes appropriate action.
class EndTimeListener {
    let media: String
    weak var playerViewController: AVPlayerViewController?
    weak var playerItem: AVPlayerItem?
    
    init(media: String, playerViewController: AVPlayerViewController, playerItem: AVPlayerItem) {
        self.media = media
        self.playerViewController = playerViewController
        self.playerItem = playerItem
        // Bug - you cannot specify the object: https://stackoverflow.com/a/51891930/59198
        NotificationCenter.default.addObserver(self, selector: #selector(playerItemDidPlayToEndTime), name: .AVPlayerItemDidPlayToEndTime, object: nil)
        
    }
    
    @objc func playerItemDidPlayToEndTime(notification: Notification) {
        guard let sender = notification.object as? AVPlayerItem else { return }
        guard sender === playerItem else { return }
        DispatchQueue.main.async { [playerViewController, media] in
            playerViewController?.dismiss(animated: true, completion: { [media] in
                SetBookmarkService.postBookmark(item: media, time: 0)
            })
        }
    }
    
    deinit {
        NotificationCenter.default.removeObserver(self)
    }
}
