Print error for configureAudio method try catch blocks. Add fallback for error: 'what' (AVAudioSessionErrorCodeUnspecified).
This commit is contained in:
parent
437a043427
commit
2fc7193580
@ -192,36 +192,51 @@ enum RCTPlayerOperations {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static func configureAudio(ignoreSilentSwitch:String, mixWithOthers:String) {
|
static func configureAudio(ignoreSilentSwitch:String, mixWithOthers:String) {
|
||||||
let session:AVAudioSession! = AVAudioSession.sharedInstance()
|
let audioSession:AVAudioSession! = AVAudioSession.sharedInstance()
|
||||||
var category:AVAudioSession.Category? = nil
|
var category:AVAudioSession.Category? = nil
|
||||||
var options:AVAudioSession.CategoryOptions? = nil
|
var options:AVAudioSession.CategoryOptions? = nil
|
||||||
|
|
||||||
if (ignoreSilentSwitch == "ignore") {
|
if (ignoreSilentSwitch == "ignore") {
|
||||||
category = AVAudioSession.Category.playback
|
category = AVAudioSession.Category.playback
|
||||||
} else if (ignoreSilentSwitch == "obey") {
|
} else if (ignoreSilentSwitch == "obey") {
|
||||||
category = AVAudioSession.Category.ambient
|
category = AVAudioSession.Category.ambient
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mixWithOthers == "mix") {
|
if (mixWithOthers == "mix") {
|
||||||
options = .mixWithOthers
|
options = .mixWithOthers
|
||||||
} else if (mixWithOthers == "duck") {
|
} else if (mixWithOthers == "duck") {
|
||||||
options = .duckOthers
|
options = .duckOthers
|
||||||
}
|
}
|
||||||
|
|
||||||
if let category = category, let options = options {
|
if let category = category, let options = options {
|
||||||
do {
|
do {
|
||||||
try session.setCategory(category, options: options)
|
try audioSession.setCategory(category, options: options)
|
||||||
} catch {
|
} 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 {
|
} else if let category = category, options == nil {
|
||||||
do {
|
do {
|
||||||
try session.setCategory(category)
|
try audioSession.setCategory(category)
|
||||||
} catch {
|
} catch {
|
||||||
|
debugPrint("[RCTPlayerOperations] Problem setting up AVAudioSession category. Error: \(error).")
|
||||||
}
|
}
|
||||||
} else if category == nil, let options = options {
|
} else if category == nil, let options = options {
|
||||||
do {
|
do {
|
||||||
try session.setCategory(session.category, options: options)
|
try audioSession.setCategory(audioSession.category, options: options)
|
||||||
} catch {
|
} catch {
|
||||||
|
debugPrint("[RCTPlayerOperations] Problem setting up AVAudioSession options. Error: \(error).")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user