From d6bae3cd076018f07556ab27af2779479bc7ff7d Mon Sep 17 00:00:00 2001 From: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> Date: Tue, 3 Sep 2024 15:33:43 +0200 Subject: [PATCH] fix(ios): fix onBandwidth update event (old ios api is deprecated and doens't work) (#4140) --- examples/basic/src/VideoPlayer.tsx | 6 ++++++ ios/Video/Features/RCTPlayerObserver.swift | 4 ++-- ios/Video/RCTVideo.swift | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/examples/basic/src/VideoPlayer.tsx b/examples/basic/src/VideoPlayer.tsx index 5784a4e31b..83e66db762 100644 --- a/examples/basic/src/VideoPlayer.tsx +++ b/examples/basic/src/VideoPlayer.tsx @@ -30,6 +30,7 @@ import Video, { type SelectedTrack, type SelectedVideoTrack, type EnumValues, + OnBandwidthUpdateData, } from 'react-native-video'; import styles from './styles'; import {type AdditionalSourceInfo} from './types'; @@ -214,6 +215,10 @@ const VideoPlayer: FC = ({}) => { console.log('onPlaybackStateChanged', data); }; + const onVideoBandwidthUpdate = (data: OnBandwidthUpdateData) => { + console.log('onVideoBandwidthUpdate', data); + } + const onFullScreenExit = () => { // iOS pauses video on exit from full screen Platform.OS === 'ios' && setPaused(true); @@ -253,6 +258,7 @@ const VideoPlayer: FC = ({}) => { onAspectRatio={onAspectRatio} onReadyForDisplay={onReadyForDisplay} onBuffer={onVideoBuffer} + onBandwidthUpdate={onVideoBandwidthUpdate} onSeek={onSeek} repeat={repeat} selectedTextTrack={selectedTextTrack} diff --git a/ios/Video/Features/RCTPlayerObserver.swift b/ios/Video/Features/RCTPlayerObserver.swift index 4f88b23d87..198a51f5c8 100644 --- a/ios/Video/Features/RCTPlayerObserver.swift +++ b/ios/Video/Features/RCTPlayerObserver.swift @@ -284,11 +284,11 @@ class RCTPlayerObserver: NSObject, AVPlayerItemMetadataOutputPushDelegate, AVPla name: NSNotification.Name.AVPlayerItemFailedToPlayToEndTime, object: nil) - NotificationCenter.default.removeObserver(_handlers, name: NSNotification.Name.AVPlayerItemNewAccessLogEntry, object: player?.currentItem) + NotificationCenter.default.removeObserver(_handlers, name: AVPlayerItem.newAccessLogEntryNotification, object: player?.currentItem) NotificationCenter.default.addObserver(_handlers, selector: #selector(RCTPlayerObserverHandlerObjc.handleAVPlayerAccess(notification:)), - name: NSNotification.Name.AVPlayerItemNewAccessLogEntry, + name: AVPlayerItem.newAccessLogEntryNotification, object: player?.currentItem) } diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index 3aaf532c8a..7ff1a7e7de 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -1661,7 +1661,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH } guard let lastEvent = accessLog.events.last else { return } - onVideoBandwidthUpdate?(["bitrate": lastEvent.observedBitrate, "target": reactTag]) + onVideoBandwidthUpdate?(["bitrate": lastEvent.indicatedBitrate, "target": reactTag]) } func handleTracksChange(playerItem _: AVPlayerItem, change _: NSKeyValueObservedChange<[AVPlayerItemTrack]>) {