Bluesky app fork with some witchin' additions 💫

[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>

authored by samuel.fm

Samuel Newman
Hailey
and committed by
GitHub
21e214c2 26d3777e

+22 -2
+11 -1
modules/expo-bluesky-swiss-army/ios/PlatformInfo/ExpoPlatformInfoModule.swift
··· 1 1 import ExpoModulesCore 2 2 3 3 public class ExpoPlatformInfoModule: Module { 4 + private var prevAudioActive: Bool? 5 + private var prevAudioCategory: AVAudioSession.Category? 6 + 4 7 public func definition() -> ModuleDefinition { 5 8 Name("ExpoPlatformInfo") 6 9 ··· 10 13 11 14 Function("setAudioCategory") { (audioCategoryString: String) in 12 15 let audioCategory = AVAudioSession.Category(rawValue: audioCategoryString) 13 - 16 + if audioCategory == self.prevAudioCategory { 17 + return 18 + } 19 + self.prevAudioCategory = audioCategory 14 20 DispatchQueue.global(qos: .background).async { 15 21 try? AVAudioSession.sharedInstance().setCategory(audioCategory) 16 22 } 17 23 } 18 24 19 25 Function("setAudioActive") { (active: Bool) in 26 + if active == self.prevAudioActive { 27 + return 28 + } 29 + self.prevAudioActive = active 20 30 if active { 21 31 DispatchQueue.global(qos: .background).async { 22 32 try? AVAudioSession.sharedInstance().setActive(true)
+1 -1
src/view/com/composer/videos/VideoPreview.tsx
··· 16 16 }) { 17 17 const player = useVideoPlayer(video.uri, player => { 18 18 player.loop = true 19 + player.muted = true 19 20 player.play() 20 - player.volume = 0 21 21 }) 22 22 23 23 return (
+3
src/view/com/util/post-embeds/VideoEmbedInner/VideoEmbedInnerNative.tsx
··· 28 28 useEffect(() => { 29 29 try { 30 30 if (isAppFocused === 'active' && isScreenFocused && !player.playing) { 31 + PlatformInfo.setAudioCategory(AudioCategory.Ambient) 32 + PlatformInfo.setAudioActive(false) 33 + player.muted = true 31 34 player.play() 32 35 } else if (player.playing) { 33 36 player.pause()
+7
src/view/com/util/post-embeds/VideoPlayerContext.tsx
··· 3 3 import {useVideoPlayer as useExpoVideoPlayer} from 'expo-video' 4 4 5 5 import {logger} from '#/logger' 6 + import { 7 + AudioCategory, 8 + PlatformInfo, 9 + } from '../../../../../modules/expo-bluesky-swiss-army' 6 10 7 11 const VideoPlayerContext = React.createContext<VideoPlayer | null>(null) 8 12 ··· 16 20 // eslint-disable-next-line @typescript-eslint/no-shadow 17 21 const player = useExpoVideoPlayer(source, player => { 18 22 try { 23 + PlatformInfo.setAudioCategory(AudioCategory.Ambient) 24 + PlatformInfo.setAudioActive(false) 25 + 19 26 player.loop = true 20 27 player.muted = true 21 28 player.play()