Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VideoPlayerView notifications don't appear to be removed #818

Open
sureshjoshi opened this issue Oct 2, 2024 · 2 comments
Open

VideoPlayerView notifications don't appear to be removed #818

sureshjoshi opened this issue Oct 2, 2024 · 2 comments

Comments

@sureshjoshi
Copy link

I noticed that registerNotifications is called every time the player is set, which happens both on play and on reset.

    private var player: AVPlayer? {
        didSet {
            registerNotifications()
        }
    }

Should this didSet have an unregisterNotifications for when you set nil maybe?

I'm running into a problem where I incessantly have onVideoFinished called every time reset and play a video.

    func play() {
        if let player = videoView.playerLayer.player{
            player.play()
        } else {
            // First run
            videoView.isLooping = configuration?.shouldLoop ?? videoView.isLooping
            videoView.onVideoFinished = { 
                print("onVideoFinished")
            }
            videoView.play()
        }

Every time I close and open/play, I get progressively more logs of onVideoFinished

@sureshjoshi
Copy link
Author

As an example, I just scrolled through a handful of videos in a collection view, and when I played my next video, I had about 50 onVideoFinished queued up and printed 🤯

I'm sure this has to do with my views being cached, but I'm also wiping out the handler during cleanup, so it's all strange 😆

@sureshjoshi
Copy link
Author

Note: I don't have a full fix yet, but as a quick workaround, I'm manually calling NotificationCenter.default.removeObserver(videoView) after I reset the videoView, and also when I'm doing any cleanup in prepareForReuse or elsewhere.

That has mitigated the problem for the most part today. Will come back to this when I get to re-factor that part of my code in the next few months.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant