Skip to content

Commit 30ee3cc

Browse files
committed
Init RouteChangeReason enum with userInfo value
Follows Apple documentation here: https://developer.apple.com/documentation/avfaudio/responding-to-audio-route-changes#Respond-to-route-changes
1 parent 05e7f2b commit 30ee3cc

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

ios/Video/RCTVideo.swift

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -401,12 +401,15 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
401401

402402
@objc
403403
func audioRouteChanged(notification: NSNotification!) {
404-
if let userInfo = notification.userInfo {
405-
let reason: AVAudioSession.RouteChangeReason! = userInfo[AVAudioSessionRouteChangeReasonKey] as? AVAudioSession.RouteChangeReason
406-
// let previousRoute:NSNumber! = userInfo[AVAudioSessionRouteChangePreviousRouteKey] as? NSNumber
407-
if reason == .oldDeviceUnavailable, let onVideoAudioBecomingNoisy {
408-
onVideoAudioBecomingNoisy(["target": reactTag as Any])
409-
}
404+
guard let userInfo = notification.userInfo,
405+
let reasonValue = userInfo[AVAudioSessionRouteChangeReasonKey] as? UInt,
406+
// let previousRouteValue: UInt = userInfo[AVAudioSessionRouteChangePreviousRouteKey] as? UInt
407+
let reason = AVAudioSession.RouteChangeReason(rawValue: reasonValue) else {
408+
return
409+
}
410+
411+
if reason == .oldDeviceUnavailable, let onVideoAudioBecomingNoisy {
412+
onVideoAudioBecomingNoisy(["target": reactTag as Any])
410413
}
411414
}
412415

0 commit comments

Comments
 (0)