Bluesky app fork with some witchin' additions 💫
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

[Video] More tweaks to `AVAudioSession` options (#4910)

authored by

Hailey and committed by
GitHub
5bfe5aa5 dd0d50a6

+74 -10
+2 -1
modules/expo-bluesky-swiss-army/index.ts
··· 1 1 import * as PlatformInfo from './src/PlatformInfo' 2 + import {AudioCategory} from './src/PlatformInfo/types' 2 3 import * as Referrer from './src/Referrer' 3 4 import * as SharedPrefs from './src/SharedPrefs' 4 5 import VisibilityView from './src/VisibilityView' 5 6 6 - export {PlatformInfo, Referrer, SharedPrefs, VisibilityView} 7 + export {AudioCategory, PlatformInfo, Referrer, SharedPrefs, VisibilityView}
+14 -2
modules/expo-bluesky-swiss-army/ios/PlatformInfo/ExpoPlatformInfoModule.swift
··· 8 8 return UIAccessibility.isReduceMotionEnabled 9 9 } 10 10 11 + Function("setAudioCategory") { (audioCategoryString: String) in 12 + let audioCategory = AVAudioSession.Category(rawValue: audioCategoryString) 13 + try? AVAudioSession.sharedInstance().setCategory(audioCategory) 14 + } 15 + 11 16 Function("setAudioMixWithOthers") { (mixWithOthers: Bool) in 12 17 var options: AVAudioSession.CategoryOptions 18 + let currentCategory = AVAudioSession.sharedInstance().category 13 19 if mixWithOthers { 14 20 options = [.mixWithOthers] 15 21 } else { 16 - options = [] 22 + options = [.duckOthers] 17 23 } 18 - try? AVAudioSession.sharedInstance().setCategory(AVAudioSession.Category.playback, mode: .default, options: options) 24 + try? AVAudioSession 25 + .sharedInstance() 26 + .setCategory( 27 + currentCategory, 28 + mode: .default, 29 + options: options 30 + ) 19 31 } 20 32 } 21 33 }
+7
modules/expo-bluesky-swiss-army/src/PlatformInfo/index.native.ts
··· 1 1 import {Platform} from 'react-native' 2 2 import {requireNativeModule} from 'expo-modules-core' 3 3 4 + import {AudioCategory} from './types' 5 + 4 6 const NativeModule = requireNativeModule('ExpoPlatformInfo') 5 7 6 8 export function getIsReducedMotionEnabled(): boolean { ··· 11 13 if (Platform.OS !== 'ios') return 12 14 NativeModule.setAudioMixWithOthers(mixWithOthers) 13 15 } 16 + 17 + export function setAudioCategory(audioCategory: AudioCategory): void { 18 + if (Platform.OS !== 'ios') return 19 + NativeModule.setAudioCategory(audioCategory) 20 + }
+14
modules/expo-bluesky-swiss-army/src/PlatformInfo/index.ts
··· 1 1 import {NotImplementedError} from '../NotImplemented' 2 + import {AudioCategory} from './types' 2 3 3 4 export function getIsReducedMotionEnabled(): boolean { 4 5 throw new NotImplementedError() 5 6 } 6 7 8 + /** 9 + * Set whether the app's audio should mix with other apps' audio. 10 + * @param mixWithOthers 11 + */ 7 12 export function setAudioMixWithOthers(mixWithOthers: boolean): void { 8 13 throw new NotImplementedError({mixWithOthers}) 9 14 } 15 + 16 + /** 17 + * Set the audio category for the app. 18 + * @param audioCategory 19 + * @platform ios 20 + */ 21 + export function setAudioCategory(audioCategory: AudioCategory): void { 22 + throw new NotImplementedError({audioCategory}) 23 + }
+5
modules/expo-bluesky-swiss-army/src/PlatformInfo/index.web.ts
··· 1 1 import {NotImplementedError} from '../NotImplemented' 2 + import {AudioCategory} from './types' 2 3 3 4 export function getIsReducedMotionEnabled(): boolean { 4 5 if (typeof window === 'undefined') { ··· 10 11 export function setAudioMixWithOthers(mixWithOthers: boolean): void { 11 12 throw new NotImplementedError({mixWithOthers}) 12 13 } 14 + 15 + export function setAudioCategory(audioCategory: AudioCategory): void { 16 + throw new NotImplementedError({audioCategory}) 17 + }
+15
modules/expo-bluesky-swiss-army/src/PlatformInfo/types.ts
··· 1 + /** 2 + * Sets the audio session category on iOS. In general, we should only need to use this for the `playback` and `ambient` 3 + * categories. This enum however includes other categories that are available in the native API for clarity and 4 + * potential future use. 5 + * @see https://developer.apple.com/documentation/avfoundation/avaudiosession/category 6 + * @platform ios 7 + */ 8 + export enum AudioCategory { 9 + Ambient = 'AVAudioSessionCategoryAmbient', 10 + Playback = 'AVAudioSessionCategoryPlayback', 11 + _SoloAmbient = 'AVAudioSessionCategorySoloAmbient', 12 + _Record = 'AVAudioSessionCategoryRecord', 13 + _PlayAndRecord = 'AVAudioSessionCategoryPlayAndRecord', 14 + _MultiRoute = 'AVAudioSessionCategoryMultiRoute', 15 + }
+2 -1
src/App.native.tsx
··· 61 61 import {Splash} from '#/Splash' 62 62 import {Provider as TourProvider} from '#/tours' 63 63 import {BackgroundNotificationPreferencesProvider} from '../modules/expo-background-notification-handler/src/BackgroundNotificationHandlerProvider' 64 - import {PlatformInfo} from '../modules/expo-bluesky-swiss-army' 64 + import {AudioCategory, PlatformInfo} from '../modules/expo-bluesky-swiss-army' 65 65 66 66 SplashScreen.preventAutoHideAsync() 67 67 ··· 158 158 const [isReady, setReady] = useState(false) 159 159 160 160 React.useEffect(() => { 161 + PlatformInfo.setAudioCategory(AudioCategory.Ambient) 161 162 PlatformInfo.setAudioMixWithOthers(true) 162 163 initPersistedState().then(() => setReady(true)) 163 164 }, [])
+15 -6
src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative.tsx
··· 12 12 import {Mute_Stroke2_Corner0_Rounded as MuteIcon} from '#/components/icons/Mute' 13 13 import {SpeakerVolumeFull_Stroke2_Corner0_Rounded as UnmuteIcon} from '#/components/icons/Speaker' 14 14 import {Text} from '#/components/Typography' 15 - import {PlatformInfo} from '../../../../../../modules/expo-bluesky-swiss-army' 15 + import { 16 + AudioCategory, 17 + PlatformInfo, 18 + } from '../../../../../../modules/expo-bluesky-swiss-army' 16 19 17 20 export function VideoEmbedInnerNative() { 18 21 const player = useVideoPlayer() ··· 39 42 style={a.flex_1} 40 43 nativeControls={true} 41 44 onEnterFullscreen={() => { 45 + PlatformInfo.setAudioCategory(AudioCategory.Playback) 42 46 PlatformInfo.setAudioMixWithOthers(false) 43 47 player.muted = false 44 48 }} 45 49 onExitFullscreen={() => { 50 + PlatformInfo.setAudioCategory(AudioCategory.Ambient) 46 51 PlatformInfo.setAudioMixWithOthers(true) 47 52 player.muted = true 48 53 }} ··· 96 101 } 97 102 }, [player]) 98 103 99 - const toggleSound = useCallback(() => { 100 - const newValue = !player.muted 104 + const toggleMuted = useCallback(() => { 105 + const muted = !player.muted 101 106 // We want to set this to the _inverse_ of the new value, because we actually want for the audio to be mixed when 102 107 // the video is muted, and vice versa. 103 - PlatformInfo.setAudioMixWithOthers(!newValue) 104 - player.muted = newValue 108 + const mix = !muted 109 + const category = muted ? AudioCategory.Ambient : AudioCategory.Playback 110 + 111 + PlatformInfo.setAudioCategory(category) 112 + PlatformInfo.setAudioMixWithOthers(mix) 113 + player.muted = muted 105 114 }, [player]) 106 115 107 116 return ( ··· 140 149 accessibilityRole="button" 141 150 /> 142 151 <Pressable 143 - onPress={toggleSound} 152 + onPress={toggleMuted} 144 153 style={{ 145 154 backgroundColor: 'rgba(0, 0, 0, 0.75)', 146 155 borderRadius: 6,