From 2fc71935805e3e87a8921af6e9cfa18b8ac7de47 Mon Sep 17 00:00:00 2001 From: Roman Melnyk Date: Fri, 3 Mar 2023 16:47:05 +0200 Subject: [PATCH 1/2] Print error for configureAudio method try catch blocks. Add fallback for error: 'what' (AVAudioSessionErrorCodeUnspecified). --- ios/Video/Features/RCTPlayerOperations.swift | 29 +++++++++++++++----- 1 file changed, 22 insertions(+), 7 deletions(-) diff --git a/ios/Video/Features/RCTPlayerOperations.swift b/ios/Video/Features/RCTPlayerOperations.swift index 8b76fafc..453a0a0c 100644 --- a/ios/Video/Features/RCTPlayerOperations.swift +++ b/ios/Video/Features/RCTPlayerOperations.swift @@ -192,36 +192,51 @@ enum RCTPlayerOperations { } static func configureAudio(ignoreSilentSwitch:String, mixWithOthers:String) { - let session:AVAudioSession! = AVAudioSession.sharedInstance() + let audioSession:AVAudioSession! = AVAudioSession.sharedInstance() var category:AVAudioSession.Category? = nil var options:AVAudioSession.CategoryOptions? = nil - + if (ignoreSilentSwitch == "ignore") { category = AVAudioSession.Category.playback } else if (ignoreSilentSwitch == "obey") { category = AVAudioSession.Category.ambient } - + if (mixWithOthers == "mix") { options = .mixWithOthers } else if (mixWithOthers == "duck") { options = .duckOthers } - + if let category = category, let options = options { do { - try session.setCategory(category, options: options) + try audioSession.setCategory(category, options: options) } catch { + debugPrint("[RCTPlayerOperations] Problem setting up AVAudioSession category and options. Error: \(error).") + // Handle specific set category abd option combination error + // setCategory:AVAudioSessionCategoryPlayback withOptions:mixWithOthers || duckOthers + // Failed to set category, error: 'what' Error Domain=NSOSStatusErrorDomain + // https://developer.apple.com/forums/thread/714598 + if #available(iOS 16.0, *) { + do { + debugPrint("[RCTPlayerOperations] Reseting AVAudioSession category to playAndRecord with defaultToSpeaker options.") + try audioSession.setCategory(AVAudioSession.Category.playAndRecord, options: AVAudioSession.CategoryOptions.defaultToSpeaker) + } catch { + debugPrint("[RCTPlayerOperations] Reseting AVAudioSession category and options problem. Error: \(error).") + } + } } } else if let category = category, options == nil { do { - try session.setCategory(category) + try audioSession.setCategory(category) } catch { + debugPrint("[RCTPlayerOperations] Problem setting up AVAudioSession category. Error: \(error).") } } else if category == nil, let options = options { do { - try session.setCategory(session.category, options: options) + try audioSession.setCategory(audioSession.category, options: options) } catch { + debugPrint("[RCTPlayerOperations] Problem setting up AVAudioSession options. Error: \(error).") } } } From 87859bcc791d896826825e0bf1296bdd972e76ff Mon Sep 17 00:00:00 2001 From: Romick2005 <17779660+Romick2005@users.noreply.github.com> Date: Wed, 5 Apr 2023 23:50:22 +0300 Subject: [PATCH 2/2] Update ios/Video/Features/RCTPlayerOperations.swift Co-authored-by: Olivier Bouillet <62574056+freeboub@users.noreply.github.com> --- ios/Video/Features/RCTPlayerOperations.swift | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ios/Video/Features/RCTPlayerOperations.swift b/ios/Video/Features/RCTPlayerOperations.swift index 453a0a0c..a6156445 100644 --- a/ios/Video/Features/RCTPlayerOperations.swift +++ b/ios/Video/Features/RCTPlayerOperations.swift @@ -213,7 +213,7 @@ enum RCTPlayerOperations { try audioSession.setCategory(category, options: options) } catch { debugPrint("[RCTPlayerOperations] Problem setting up AVAudioSession category and options. Error: \(error).") - // Handle specific set category abd option combination error + // Handle specific set category and option combination error // setCategory:AVAudioSessionCategoryPlayback withOptions:mixWithOthers || duckOthers // Failed to set category, error: 'what' Error Domain=NSOSStatusErrorDomain // https://developer.apple.com/forums/thread/714598