-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Pause video on end reached, don't remove listeners #4218
Pause video on end reached, don't remove listeners #4218
Conversation
This fixes an issue when seeking back to the beginning results in no `onProgress` events being fired.
@@ -1631,7 +1631,8 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH | |||
} | |||
) | |||
} else { | |||
_playerObserver.removePlayerTimeObserver() | |||
_player?.pause() | |||
_player?.rate = 0.0 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should avoid removing the time observer to keep the player in memory and prevent reinitialization, ensuring smoother playback and better performance.
_player?.rate = 0.0 | |
_player?.pause() | |
_player?.rate = 0.0 | |
_playerObserver.removePlayerTimeObserver() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that this change is good! But we need to move _playerObserver.removePlayerTimeObserver()
to other place as this was the only place where it was called. We probably should move it do deinit
- Can you handle it @sharnik ?
On my side I think you can just remove the observer, why do you force pause ? |
@freeboub Removing the observer is the problem here - if I do that and user decides to replay the video, no progress events are triggered, even though the video is playing. @KrzysztofMoch I'll add the |
@sharnik I agree, you should remove the observer ! |
If I don't pause, the progress events keep coming in, even though the video is at its end and nothing's playing. |
@sharnik OK, That's clear! I don't think that this pause is the good way to handle this side effect. |
@KrzysztofMoch I've checked and when And This should be enough. No need to add additional manual cleanup, right? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah make sense - Thanks for PR!
Problem
That issues exists on iOS only, on Android it behaves us expected.
When you play a video all the way till the end,
onEndReached
we'll remove the time observers that update theonProgress
handlers. But, if the user just seeks back to the beginning of the video (or anywhere on the timeline), the video will keep playing (as it was never stopped), but noonProgress
callbacks/events will be triggered.Solution
On reaching the end of the video (unless set to repeat) instead of removing the time observers we just pause it. This will stop the
onProgress
events firing after the video finished. If the user chooses to seek back on the timeline to replay the video, they'd have to press "play" and the video will start normally and theonProgress
events will fire correctly.Test plan
This can be checked by running a simple player on iOS that is:
controls
onProgress
callback (for example:onProgress={() => { console.log('test') }}
)And then watching (or seeking) all the way till the end and then (without pausing or resuming it) seeking back to the beginning.