 public class BackgroundVideo {
     private var player = AVPlayer()
 
+    private var willLoopVideo = true
+
+    /// Initializes a BackgroundVideo instance.
+    public init() {
+        NotificationCenter.default.addObserver(self,
+                                               selector: #selector(restartVideo),
+                                               name: NSNotification.Name.AVPlayerItemDidPlayToEndTime,
+                                               object: nil)
+    }
+
     /// Plays a video on a given UIView.
     ///
     /// - Parameters:

    ///     - opacity: The opacity of the layer, as a value between zero and one.
    ///                Defaults to one. Specifying a value outside the [0,1]
    ///                range will give undefined results.
    ///     - loopVideo: Bool indicating whether video should restart when finished.
    ///                  Defaults to true.
    public func play(view: UIView,
                     videoName: String,
                     videoType: String,
                     isMuted: Bool = true,
                     opacity: Float = 1.0,
                     loopVideo: Bool = true) {
        guard let path = Bundle.main.path(forResource: videoName, ofType: videoType) else {
            print("BackgroundVideo: [ERROR] could not find video")
            return

        layer.zPosition = -1
        view.layer.addSublayer(layer)

        self.willLoopVideo = willLoopVideo
    }

    @objc private dynamic func restartVideo() {
        if willLoopVideo {
            player.seek(to: kCMTimeZero)
            player.play()
        }
    }

    deinit {
        NotificationCenter.default.removeObserver(self)
    }
}
