From 286418e4a5a4331257d39012b0ef9d4d17519af8 Mon Sep 17 00:00:00 2001 From: Krzysztof Moch Date: Tue, 24 Oct 2023 22:10:29 +0200 Subject: [PATCH] fix(ios): remove false calls at `onPlaybackRateChange` (#3306) --- ios/Video/Features/RCTPlayerObserver.swift | 2 +- ios/Video/RCTVideo.swift | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/ios/Video/Features/RCTPlayerObserver.swift b/ios/Video/Features/RCTPlayerObserver.swift index 1c512bcf..f7120632 100644 --- a/ios/Video/Features/RCTPlayerObserver.swift +++ b/ios/Video/Features/RCTPlayerObserver.swift @@ -94,7 +94,7 @@ class RCTPlayerObserver: NSObject { return } - _playerRateChangeObserver = player.observe(\.rate, changeHandler: _handlers.handlePlaybackRateChange) + _playerRateChangeObserver = player.observe(\.rate, options: [.old], changeHandler: _handlers.handlePlaybackRateChange) _playerExternalPlaybackActiveObserver = player.observe(\.isExternalPlaybackActive, changeHandler: _handlers.handleExternalPlaybackActiveChange) } diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index 6a33bdb9..7696e799 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -1221,6 +1221,10 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH func handlePlaybackRateChange(player: AVPlayer, change: NSKeyValueObservedChange) { guard let _player = _player else { return } + if(player.rate == change.oldValue && change.oldValue != nil) { + return + } + onPlaybackRateChange?(["playbackRate": NSNumber(value: _player.rate), "target": reactTag as Any])