fix(ios): fix onBandwidth update event (old ios api is deprecated and doens't work) (#4140)
This commit is contained in:
parent
c51c061f43
commit
d6bae3cd07
@ -30,6 +30,7 @@ import Video, {
|
|||||||
type SelectedTrack,
|
type SelectedTrack,
|
||||||
type SelectedVideoTrack,
|
type SelectedVideoTrack,
|
||||||
type EnumValues,
|
type EnumValues,
|
||||||
|
OnBandwidthUpdateData,
|
||||||
} from 'react-native-video';
|
} from 'react-native-video';
|
||||||
import styles from './styles';
|
import styles from './styles';
|
||||||
import {type AdditionalSourceInfo} from './types';
|
import {type AdditionalSourceInfo} from './types';
|
||||||
@ -214,6 +215,10 @@ const VideoPlayer: FC<Props> = ({}) => {
|
|||||||
console.log('onPlaybackStateChanged', data);
|
console.log('onPlaybackStateChanged', data);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
const onVideoBandwidthUpdate = (data: OnBandwidthUpdateData) => {
|
||||||
|
console.log('onVideoBandwidthUpdate', data);
|
||||||
|
}
|
||||||
|
|
||||||
const onFullScreenExit = () => {
|
const onFullScreenExit = () => {
|
||||||
// iOS pauses video on exit from full screen
|
// iOS pauses video on exit from full screen
|
||||||
Platform.OS === 'ios' && setPaused(true);
|
Platform.OS === 'ios' && setPaused(true);
|
||||||
@ -253,6 +258,7 @@ const VideoPlayer: FC<Props> = ({}) => {
|
|||||||
onAspectRatio={onAspectRatio}
|
onAspectRatio={onAspectRatio}
|
||||||
onReadyForDisplay={onReadyForDisplay}
|
onReadyForDisplay={onReadyForDisplay}
|
||||||
onBuffer={onVideoBuffer}
|
onBuffer={onVideoBuffer}
|
||||||
|
onBandwidthUpdate={onVideoBandwidthUpdate}
|
||||||
onSeek={onSeek}
|
onSeek={onSeek}
|
||||||
repeat={repeat}
|
repeat={repeat}
|
||||||
selectedTextTrack={selectedTextTrack}
|
selectedTextTrack={selectedTextTrack}
|
||||||
|
@ -284,11 +284,11 @@ class RCTPlayerObserver: NSObject, AVPlayerItemMetadataOutputPushDelegate, AVPla
|
|||||||
name: NSNotification.Name.AVPlayerItemFailedToPlayToEndTime,
|
name: NSNotification.Name.AVPlayerItemFailedToPlayToEndTime,
|
||||||
object: nil)
|
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,
|
NotificationCenter.default.addObserver(_handlers,
|
||||||
selector: #selector(RCTPlayerObserverHandlerObjc.handleAVPlayerAccess(notification:)),
|
selector: #selector(RCTPlayerObserverHandlerObjc.handleAVPlayerAccess(notification:)),
|
||||||
name: NSNotification.Name.AVPlayerItemNewAccessLogEntry,
|
name: AVPlayerItem.newAccessLogEntryNotification,
|
||||||
object: player?.currentItem)
|
object: player?.currentItem)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1661,7 +1661,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
|
|
||||||
guard let lastEvent = accessLog.events.last else { return }
|
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]>) {
|
func handleTracksChange(playerItem _: AVPlayerItem, change _: NSKeyValueObservedChange<[AVPlayerItemTrack]>) {
|
||||||
|
Loading…
Reference in New Issue
Block a user