about summary refs log tree commit diff
diff options
context:
space:
mode:
authorHailey <me@haileyok.com>2024-08-09 16:52:23 -0700
committerGitHub <noreply@github.com>2024-08-09 16:52:23 -0700
commit65d6e561d429d6759d1eef674a964d1109a1afeb (patch)
tree083839fab56df7b13afcac312cff8aa22f05e6ac
parentc2131bb0392487f11b0c31fe68fdd3e847d62142 (diff)
downloadvoidsky-65d6e561d429d6759d1eef674a964d1109a1afeb.tar.zst
[Video] Resume background audio whenever muting video audio (#4915)
-rw-r--r--modules/expo-bluesky-swiss-army/ios/PlatformInfo/ExpoPlatformInfoModule.swift21
-rw-r--r--modules/expo-bluesky-swiss-army/src/PlatformInfo/index.native.ts4
-rw-r--r--modules/expo-bluesky-swiss-army/src/PlatformInfo/index.ts8
-rw-r--r--modules/expo-bluesky-swiss-army/src/PlatformInfo/index.web.ts4
-rw-r--r--src/App.native.tsx2
-rw-r--r--src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative.tsx6
6 files changed, 28 insertions, 17 deletions
diff --git a/modules/expo-bluesky-swiss-army/ios/PlatformInfo/ExpoPlatformInfoModule.swift b/modules/expo-bluesky-swiss-army/ios/PlatformInfo/ExpoPlatformInfoModule.swift
index 471f1438b..7fd60e5fa 100644
--- a/modules/expo-bluesky-swiss-army/ios/PlatformInfo/ExpoPlatformInfoModule.swift
+++ b/modules/expo-bluesky-swiss-army/ios/PlatformInfo/ExpoPlatformInfoModule.swift
@@ -13,20 +13,29 @@ public class ExpoPlatformInfoModule: Module {
       try? AVAudioSession.sharedInstance().setCategory(audioCategory)
     }
 
-    Function("setAudioMixWithOthers") { (mixWithOthers: Bool) in
-      var options: AVAudioSession.CategoryOptions
+    Function("setAudioActive") { (active: Bool) in
+      var categoryOptions: AVAudioSession.CategoryOptions
       let currentCategory = AVAudioSession.sharedInstance().category
-      if mixWithOthers {
-        options = [.mixWithOthers]
+
+      if active {
+        categoryOptions = [.mixWithOthers]
+        try? AVAudioSession.sharedInstance().setActive(true)
       } else {
-        options = [.duckOthers]
+        categoryOptions = [.duckOthers]
+        try? AVAudioSession
+          .sharedInstance()
+          .setActive(
+            false,
+            options: [.notifyOthersOnDeactivation]
+          )
       }
+
       try? AVAudioSession
         .sharedInstance()
         .setCategory(
           currentCategory,
           mode: .default,
-          options: options
+          options: categoryOptions
         )
     }
   }
diff --git a/modules/expo-bluesky-swiss-army/src/PlatformInfo/index.native.ts b/modules/expo-bluesky-swiss-army/src/PlatformInfo/index.native.ts
index ba9dddf82..b515206d9 100644
--- a/modules/expo-bluesky-swiss-army/src/PlatformInfo/index.native.ts
+++ b/modules/expo-bluesky-swiss-army/src/PlatformInfo/index.native.ts
@@ -9,9 +9,9 @@ export function getIsReducedMotionEnabled(): boolean {
   return NativeModule.getIsReducedMotionEnabled()
 }
 
-export function setAudioMixWithOthers(mixWithOthers: boolean): void {
+export function setAudioActive(active: boolean): void {
   if (Platform.OS !== 'ios') return
-  NativeModule.setAudioMixWithOthers(mixWithOthers)
+  NativeModule.setAudioActive(active)
 }
 
 export function setAudioCategory(audioCategory: AudioCategory): void {
diff --git a/modules/expo-bluesky-swiss-army/src/PlatformInfo/index.ts b/modules/expo-bluesky-swiss-army/src/PlatformInfo/index.ts
index 5659339fb..81f8c45f4 100644
--- a/modules/expo-bluesky-swiss-army/src/PlatformInfo/index.ts
+++ b/modules/expo-bluesky-swiss-army/src/PlatformInfo/index.ts
@@ -6,11 +6,13 @@ export function getIsReducedMotionEnabled(): boolean {
 }
 
 /**
- * Set whether the app's audio should mix with other apps' audio.
+ * Set whether the app's audio should mix with other apps' audio. Will also resume background music playback when `false`
+ * if it was previously playing.
  * @param mixWithOthers
+ * @see https://developer.apple.com/documentation/avfaudio/avaudiosession/setactiveoptions/1616603-notifyothersondeactivation
  */
-export function setAudioMixWithOthers(mixWithOthers: boolean): void {
-  throw new NotImplementedError({mixWithOthers})
+export function setAudioActive(active: boolean): void {
+  throw new NotImplementedError({active})
 }
 
 /**
diff --git a/modules/expo-bluesky-swiss-army/src/PlatformInfo/index.web.ts b/modules/expo-bluesky-swiss-army/src/PlatformInfo/index.web.ts
index cb64d00ce..61412753c 100644
--- a/modules/expo-bluesky-swiss-army/src/PlatformInfo/index.web.ts
+++ b/modules/expo-bluesky-swiss-army/src/PlatformInfo/index.web.ts
@@ -8,8 +8,8 @@ export function getIsReducedMotionEnabled(): boolean {
   return window.matchMedia('(prefers-reduced-motion: reduce)').matches
 }
 
-export function setAudioMixWithOthers(mixWithOthers: boolean): void {
-  throw new NotImplementedError({mixWithOthers})
+export function setAudioActive(active: boolean): void {
+  throw new NotImplementedError({active})
 }
 
 export function setAudioCategory(audioCategory: AudioCategory): void {
diff --git a/src/App.native.tsx b/src/App.native.tsx
index 71b53e7a3..8e7c53b93 100644
--- a/src/App.native.tsx
+++ b/src/App.native.tsx
@@ -159,7 +159,7 @@ function App() {
 
   React.useEffect(() => {
     PlatformInfo.setAudioCategory(AudioCategory.Ambient)
-    PlatformInfo.setAudioMixWithOthers(true)
+    PlatformInfo.setAudioActive(true)
     initPersistedState().then(() => setReady(true))
   }, [])
 
diff --git a/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative.tsx b/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative.tsx
index 33148da01..0b48edf79 100644
--- a/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative.tsx
+++ b/src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative.tsx
@@ -60,12 +60,12 @@ export function VideoEmbedInnerNative() {
         nativeControls={true}
         onEnterFullscreen={() => {
           PlatformInfo.setAudioCategory(AudioCategory.Playback)
-          PlatformInfo.setAudioMixWithOthers(false)
+          PlatformInfo.setAudioActive(false)
           player.muted = false
         }}
         onExitFullscreen={() => {
           PlatformInfo.setAudioCategory(AudioCategory.Ambient)
-          PlatformInfo.setAudioMixWithOthers(true)
+          PlatformInfo.setAudioActive(true)
           player.muted = true
           if (!player.playing) player.play()
         }}
@@ -139,7 +139,7 @@ function Controls({
     const category = muted ? AudioCategory.Ambient : AudioCategory.Playback
 
     PlatformInfo.setAudioCategory(category)
-    PlatformInfo.setAudioMixWithOthers(mix)
+    PlatformInfo.setAudioActive(mix)
     player.muted = muted
   }, [player])