Fix: iOS - audio does not work with headphones (#3284)
* Fix: Make AVAudioSession.Category.playAndRecord opt-in * Fix: Call configureAudio when audioOutput is changed * Update CHANGELOG.md
This commit is contained in:
parent
1f0137608a
commit
0ad2e52499
@ -1,6 +1,7 @@
|
|||||||
## Changelog
|
## Changelog
|
||||||
|
|
||||||
## Next
|
## Next
|
||||||
|
- iOS: Fix audio session category when not using the audioOutput prop
|
||||||
- All: add built-in typescript support [#3266](https://github.com/react-native-video/react-native-video/pull/3266)
|
- All: add built-in typescript support [#3266](https://github.com/react-native-video/react-native-video/pull/3266)
|
||||||
- iOS, Android: expose playback functions to ref [#3245](https://github.com/react-native-video/react-native-video/pull/3245)
|
- iOS, Android: expose playback functions to ref [#3245](https://github.com/react-native-video/react-native-video/pull/3245)
|
||||||
- Windows: fix build error from over-specified SDK version [#3246](https://github.com/react-native-video/react-native-video/pull/3246)
|
- Windows: fix build error from over-specified SDK version [#3246](https://github.com/react-native-video/react-native-video/pull/3246)
|
||||||
|
@ -191,13 +191,13 @@ enum RCTPlayerOperations {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static func configureAudio(ignoreSilentSwitch:String, mixWithOthers:String) {
|
static func configureAudio(ignoreSilentSwitch:String, mixWithOthers:String, audioOutput:String) {
|
||||||
let audioSession: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.playAndRecord
|
category = audioOutput == "earpiece" ? AVAudioSession.Category.playAndRecord : AVAudioSession.Category.playback
|
||||||
} else if (ignoreSilentSwitch == "obey") {
|
} else if (ignoreSilentSwitch == "obey") {
|
||||||
category = AVAudioSession.Category.ambient
|
category = AVAudioSession.Category.ambient
|
||||||
}
|
}
|
||||||
@ -221,7 +221,7 @@ enum RCTPlayerOperations {
|
|||||||
if #available(iOS 16.0, *) {
|
if #available(iOS 16.0, *) {
|
||||||
do {
|
do {
|
||||||
debugPrint("[RCTPlayerOperations] Reseting AVAudioSession category to playAndRecord with defaultToSpeaker options.")
|
debugPrint("[RCTPlayerOperations] Reseting AVAudioSession category to playAndRecord with defaultToSpeaker options.")
|
||||||
try audioSession.setCategory(AVAudioSession.Category.playAndRecord, options: AVAudioSession.CategoryOptions.defaultToSpeaker)
|
try audioSession.setCategory(audioOutput == "earpiece" ? AVAudioSession.Category.playAndRecord : AVAudioSession.Category.playback, options: AVAudioSession.CategoryOptions.defaultToSpeaker)
|
||||||
} catch {
|
} catch {
|
||||||
debugPrint("[RCTPlayerOperations] Reseting AVAudioSession category and options problem. Error: \(error).")
|
debugPrint("[RCTPlayerOperations] Reseting AVAudioSession category and options problem. Error: \(error).")
|
||||||
}
|
}
|
||||||
|
@ -488,7 +488,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
@objc
|
@objc
|
||||||
func setIgnoreSilentSwitch(_ ignoreSilentSwitch:String?) {
|
func setIgnoreSilentSwitch(_ ignoreSilentSwitch:String?) {
|
||||||
_ignoreSilentSwitch = ignoreSilentSwitch
|
_ignoreSilentSwitch = ignoreSilentSwitch
|
||||||
RCTPlayerOperations.configureAudio(ignoreSilentSwitch:_ignoreSilentSwitch, mixWithOthers:_mixWithOthers)
|
RCTPlayerOperations.configureAudio(ignoreSilentSwitch:_ignoreSilentSwitch, mixWithOthers:_mixWithOthers, audioOutput:_audioOutput)
|
||||||
applyModifiers()
|
applyModifiers()
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -510,7 +510,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
_player?.rate = 0.0
|
_player?.rate = 0.0
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
RCTPlayerOperations.configureAudio(ignoreSilentSwitch:_ignoreSilentSwitch, mixWithOthers:_mixWithOthers)
|
RCTPlayerOperations.configureAudio(ignoreSilentSwitch:_ignoreSilentSwitch, mixWithOthers:_mixWithOthers, audioOutput:_audioOutput)
|
||||||
|
|
||||||
if _adPlaying {
|
if _adPlaying {
|
||||||
#if USE_GOOGLE_IMA
|
#if USE_GOOGLE_IMA
|
||||||
@ -583,6 +583,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
@objc
|
@objc
|
||||||
func setAudioOutput(_ audioOutput:String) {
|
func setAudioOutput(_ audioOutput:String) {
|
||||||
_audioOutput = audioOutput
|
_audioOutput = audioOutput
|
||||||
|
RCTPlayerOperations.configureAudio(ignoreSilentSwitch:_ignoreSilentSwitch, mixWithOthers:_mixWithOthers, audioOutput:_audioOutput)
|
||||||
do {
|
do {
|
||||||
if audioOutput == "speaker" {
|
if audioOutput == "speaker" {
|
||||||
#if os(iOS)
|
#if os(iOS)
|
||||||
|
Loading…
Reference in New Issue
Block a user