[Video] Say No to Audio (Disable `expo-video` `AudioSession` management) (#5101)

zio/stable
Hailey 2024-09-03 08:33:21 -07:00 committed by GitHub
parent 0e1de19903
commit 05e61346b8
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 121 additions and 28 deletions

View File

@ -193,7 +193,7 @@ index a951d80..3932535 100644
} }
diff --git a/node_modules/expo-video/build/VideoPlayer.types.d.ts b/node_modules/expo-video/build/VideoPlayer.types.d.ts diff --git a/node_modules/expo-video/build/VideoPlayer.types.d.ts b/node_modules/expo-video/build/VideoPlayer.types.d.ts
index a09fcfe..65fe29a 100644 index a09fcfe..5eac9e5 100644
--- a/node_modules/expo-video/build/VideoPlayer.types.d.ts --- a/node_modules/expo-video/build/VideoPlayer.types.d.ts
+++ b/node_modules/expo-video/build/VideoPlayer.types.d.ts +++ b/node_modules/expo-video/build/VideoPlayer.types.d.ts
@@ -128,6 +128,8 @@ export type VideoPlayerEvents = { @@ -128,6 +128,8 @@ export type VideoPlayerEvents = {
@ -219,6 +219,96 @@ index cb9ca6d..ed8bb7e 100644
} }
//# sourceMappingURL=VideoView.types.d.ts.map //# sourceMappingURL=VideoView.types.d.ts.map
\ No newline at end of file \ No newline at end of file
diff --git a/node_modules/expo-video/ios/VideoManager.swift b/node_modules/expo-video/ios/VideoManager.swift
index 094a8b0..412fd0c 100644
--- a/node_modules/expo-video/ios/VideoManager.swift
+++ b/node_modules/expo-video/ios/VideoManager.swift
@@ -51,45 +51,45 @@ class VideoManager {
// MARK: - Audio Session Management
internal func setAppropriateAudioSessionOrWarn() {
- let audioSession = AVAudioSession.sharedInstance()
- var audioSessionCategoryOptions: AVAudioSession.CategoryOptions = []
-
- let isAnyPlayerPlaying = videoPlayers.allObjects.contains { player in
- player.isPlaying
- }
- let areAllPlayersMuted = videoPlayers.allObjects.allSatisfy { player in
- player.isMuted
- }
- let needsPiPSupport = videoViews.allObjects.contains { view in
- view.allowPictureInPicture
- }
- let anyPlayerShowsNotification = videoPlayers.allObjects.contains { player in
- player.showNowPlayingNotification
- }
- // The notification won't be shown if we allow the audio to mix with others
- let shouldAllowMixing = (!isAnyPlayerPlaying || areAllPlayersMuted) && !anyPlayerShowsNotification
- let isOutputtingAudio = !areAllPlayersMuted && isAnyPlayerPlaying
- let shouldUpdateToAllowMixing = !audioSession.categoryOptions.contains(.mixWithOthers) && shouldAllowMixing
-
- if shouldAllowMixing {
- audioSessionCategoryOptions.insert(.mixWithOthers)
- }
-
- if isOutputtingAudio || needsPiPSupport || shouldUpdateToAllowMixing || anyPlayerShowsNotification {
- do {
- try audioSession.setCategory(.playback, mode: .moviePlayback)
- } catch {
- log.warn("Failed to set audio session category. This might cause issues with audio playback and Picture in Picture. \(error.localizedDescription)")
- }
- }
-
- // Make sure audio session is active if any video is playing
- if isAnyPlayerPlaying {
- do {
- try audioSession.setActive(true)
- } catch {
- log.warn("Failed to activate the audio session. This might cause issues with audio playback. \(error.localizedDescription)")
- }
- }
+// let audioSession = AVAudioSession.sharedInstance()
+// var audioSessionCategoryOptions: AVAudioSession.CategoryOptions = []
+//
+// let isAnyPlayerPlaying = videoPlayers.allObjects.contains { player in
+// player.isPlaying
+// }
+// let areAllPlayersMuted = videoPlayers.allObjects.allSatisfy { player in
+// player.isMuted
+// }
+// let needsPiPSupport = videoViews.allObjects.contains { view in
+// view.allowPictureInPicture
+// }
+// let anyPlayerShowsNotification = videoPlayers.allObjects.contains { player in
+// player.showNowPlayingNotification
+// }
+// // The notification won't be shown if we allow the audio to mix with others
+// let shouldAllowMixing = (!isAnyPlayerPlaying || areAllPlayersMuted) && !anyPlayerShowsNotification
+// let isOutputtingAudio = !areAllPlayersMuted && isAnyPlayerPlaying
+// let shouldUpdateToAllowMixing = !audioSession.categoryOptions.contains(.mixWithOthers) && shouldAllowMixing
+//
+// if shouldAllowMixing {
+// audioSessionCategoryOptions.insert(.mixWithOthers)
+// }
+//
+// if isOutputtingAudio || needsPiPSupport || shouldUpdateToAllowMixing || anyPlayerShowsNotification {
+// do {
+// try audioSession.setCategory(.playback, mode: .moviePlayback)
+// } catch {
+// log.warn("Failed to set audio session category. This might cause issues with audio playback and Picture in Picture. \(error.localizedDescription)")
+// }
+// }
+//
+// // Make sure audio session is active if any video is playing
+// if isAnyPlayerPlaying {
+// do {
+// try audioSession.setActive(true)
+// } catch {
+// log.warn("Failed to activate the audio session. This might cause issues with audio playback. \(error.localizedDescription)")
+// }
+// }
}
}
diff --git a/node_modules/expo-video/ios/VideoModule.swift b/node_modules/expo-video/ios/VideoModule.swift diff --git a/node_modules/expo-video/ios/VideoModule.swift b/node_modules/expo-video/ios/VideoModule.swift
index c537a12..e4a918f 100644 index c537a12..e4a918f 100644
--- a/node_modules/expo-video/ios/VideoModule.swift --- a/node_modules/expo-video/ios/VideoModule.swift
@ -235,7 +325,7 @@ index c537a12..e4a918f 100644
Prop("player") { (view, player: VideoPlayer?) in Prop("player") { (view, player: VideoPlayer?) in
diff --git a/node_modules/expo-video/ios/VideoPlayer.swift b/node_modules/expo-video/ios/VideoPlayer.swift diff --git a/node_modules/expo-video/ios/VideoPlayer.swift b/node_modules/expo-video/ios/VideoPlayer.swift
index 3315b88..f482390 100644 index 3315b88..733ab1f 100644
--- a/node_modules/expo-video/ios/VideoPlayer.swift --- a/node_modules/expo-video/ios/VideoPlayer.swift
+++ b/node_modules/expo-video/ios/VideoPlayer.swift +++ b/node_modules/expo-video/ios/VideoPlayer.swift
@@ -185,6 +185,10 @@ internal final class VideoPlayer: SharedRef<AVPlayer>, Hashable, VideoPlayerObse @@ -185,6 +185,10 @@ internal final class VideoPlayer: SharedRef<AVPlayer>, Hashable, VideoPlayerObse
@ -250,7 +340,7 @@ index 3315b88..f482390 100644
if self.appContext != nil { if self.appContext != nil {
self.emit(event: event, arguments: repeat each arguments) self.emit(event: event, arguments: repeat each arguments)
diff --git a/node_modules/expo-video/ios/VideoPlayerObserver.swift b/node_modules/expo-video/ios/VideoPlayerObserver.swift diff --git a/node_modules/expo-video/ios/VideoPlayerObserver.swift b/node_modules/expo-video/ios/VideoPlayerObserver.swift
index d289e26..de9a26f 100644 index d289e26..ea4d96f 100644
--- a/node_modules/expo-video/ios/VideoPlayerObserver.swift --- a/node_modules/expo-video/ios/VideoPlayerObserver.swift
+++ b/node_modules/expo-video/ios/VideoPlayerObserver.swift +++ b/node_modules/expo-video/ios/VideoPlayerObserver.swift
@@ -21,6 +21,7 @@ protocol VideoPlayerObserverDelegate: AnyObject { @@ -21,6 +21,7 @@ protocol VideoPlayerObserverDelegate: AnyObject {

View File

@ -4,3 +4,6 @@
This patch adds two props to `VideoView`: `onEnterFullscreen` and `onExitFullscreen` which do exactly what they say on This patch adds two props to `VideoView`: `onEnterFullscreen` and `onExitFullscreen` which do exactly what they say on
the tin. the tin.
This patch also removes the audio session management that Expo does on its own, as we handle audio session management
ourselves.