[Video] set audio category to ambient every time a new player is made (#4934)
* set auto category to ambient every time a new player is made * mute on foregrounding * remember previous state --------- Co-authored-by: Samuel Newman <10959775+mozzius@users.noreply.github.com> Co-authored-by: Hailey <me@haileyok.com>
This commit is contained in:
parent
26d3777ecc
commit
21e214c235
4 changed files with 22 additions and 2 deletions
|
@ -1,6 +1,9 @@
|
|||
import ExpoModulesCore
|
||||
|
||||
public class ExpoPlatformInfoModule: Module {
|
||||
private var prevAudioActive: Bool?
|
||||
private var prevAudioCategory: AVAudioSession.Category?
|
||||
|
||||
public func definition() -> ModuleDefinition {
|
||||
Name("ExpoPlatformInfo")
|
||||
|
||||
|
@ -10,13 +13,20 @@ public class ExpoPlatformInfoModule: Module {
|
|||
|
||||
Function("setAudioCategory") { (audioCategoryString: String) in
|
||||
let audioCategory = AVAudioSession.Category(rawValue: audioCategoryString)
|
||||
|
||||
if audioCategory == self.prevAudioCategory {
|
||||
return
|
||||
}
|
||||
self.prevAudioCategory = audioCategory
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
try? AVAudioSession.sharedInstance().setCategory(audioCategory)
|
||||
}
|
||||
}
|
||||
|
||||
Function("setAudioActive") { (active: Bool) in
|
||||
if active == self.prevAudioActive {
|
||||
return
|
||||
}
|
||||
self.prevAudioActive = active
|
||||
if active {
|
||||
DispatchQueue.global(qos: .background).async {
|
||||
try? AVAudioSession.sharedInstance().setActive(true)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue