         guard let player = player, player.observationInfo != nil else { return }
         player.removeObserver(self, forKeyPath: "currentItem.playbackLikelyToKeepUp")
         player.removeObserver(self, forKeyPath: "currentItem.playbackBufferEmpty")
-        player.removeObserver(self, forKeyPath: "externalPlaybackActive")
         player.removeObserver(self, forKeyPath: "rate")
         if let timeObserver = timeObserver {
             player.removeTimeObserver(timeObserver)

        }
    }

    private func handleExternalPlaybackActiveEvent() {
        guard let isExternalPlaybackActive = player?.isExternalPlaybackActive else { return }

        if isExternalPlaybackActive {
            enableBackgroundSession()
        } else {
            restoreBackgroundSession()
        }
        trigger(.didUpdateAirPlayStatus, userInfo: ["externalPlaybackActive": isExternalPlaybackActive])
    }

    func handleDvrAvailabilityChange() {
        if lastDvrAvailability != isDvrAvailable {
            trigger(.didChangeDvrAvailability, userInfo: ["available": isDvrAvailable])

        handleDvrAvailabilityChange()
    }

    private func handleExternalPlaybackActiveEvent(player: AVPlayer, changes: Any) {
        if player.isExternalPlaybackActive {
            enableBackgroundSession()
        } else {
            restoreBackgroundSession()
        }
        trigger(.didUpdateAirPlayStatus, userInfo: ["externalPlaybackActive": player.isExternalPlaybackActive])
    }

    private func enableBackgroundSession() {
        backgroundSessionBackup = AVAudioSession.sharedInstance().category
        changeBackgroundSession(to: .playback)
    }

    private func restoreBackgroundSession() {
        if let backgroundSession = backgroundSessionBackup {
            changeBackgroundSession(to: backgroundSession)
        }
    }

    private func changeBackgroundSession(to category: AVAudioSession.Category) {
        do {
            try AVAudioSession.sharedInstance().setCategory(category, mode: .default, options: [.allowAirPlay])
        } catch {
            print("It was not possible to set the audio session category")
        }
    }

    private func handlePlayerRateChanged(player: AVPlayer, changes: Any) {
        if player.rate == 0 && playerStatus != .unknown && state != .idle {
            updateState(.paused)
        }
    }

    private func didFinishedItem(from notification: NSNotification?) -> Bool {
        guard let object = notification?.object as? AVPlayerItem,
            let item = player?.currentItem,
