feat(ios): allow to disable audio sessions management (#4492)

* feat(ios): allow to disable audio sessions management

* chore: lint code

* chore: fix alphabetical order
This commit is contained in:
Krzysztof Moch
2025-04-06 16:39:18 +02:00
committed by GitHub
parent a849cc19e8
commit 8836362609
6 changed files with 40 additions and 0 deletions
+15
View File
@@ -271,6 +271,20 @@ Determines if the player should throw an error when the network connection is lo
---
### `disableAudioSessionManagement`
<PlatformsList types={['iOS']} />
Disable audio session management in library (for all views).
- **true** - Disable audio session management in the library.
- **false (default)** - Enable audio session management in the library.
> ⚠️ This prop disables audio session management in the library. You only should use this prop if you are managing the audio session yourself.
> You can encounter issues with other features, like background audio, if you don't properly manage the audio session.
---
### `drm`
> [!WARNING]
@@ -1183,6 +1197,7 @@ To customize the notification controls, you can use the `metadata` property in t
```
---
### `useSecureView`
> [!WARNING]
+16
View File
@@ -8,6 +8,12 @@ class AudioSessionManager {
private var isAudioSessionActive = false
private var remoteControlEventsActive = false
private var isAudioSessionManagementDisabled: Bool {
return videoViews.allObjects.contains { view in
return view._disableAudioSessionManagement == true
}
}
private init() {
// Subscribe to audio interruption notifications
NotificationCenter.default.addObserver(
@@ -69,6 +75,11 @@ class AudioSessionManager {
// Handle remote control events from NowPlayingInfoCenterManager
func setRemoteControlEventsActive(_ active: Bool) {
if isAudioSessionManagementDisabled {
// AUDIO SESSION MANAGEMENT DISABLED BY USER
return
}
remoteControlEventsActive = active
if active {
@@ -130,6 +141,11 @@ class AudioSessionManager {
let canAllowMixing = !anyPlayerShowNotificationControls && !anyPlayerNeedsBackgroundPlayback
if isAudioSessionManagementDisabled {
// AUDIO SESSION MANAGEMENT DISABLED BY USER
return
}
if canAllowMixing {
let shouldEnableMixing = videoViews.allObjects.contains { view in
return view._mixWithOthers == "mix"
+6
View File
@@ -60,6 +60,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
private var _filterEnabled = false
private var _presentingViewController: UIViewController?
private var _startPosition: Float64 = -1
var _disableAudioSessionManagement: Bool = false
var _showNotificationControls = false
// Buffer last bitrate value received. Initialized to -2 to ensure -1 (sometimes reported by AVPlayer) is not missed
private var _lastBitrate = -2.0
@@ -1233,6 +1234,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
}
}
@objc
func setDisableAudioSessionManagement(_ disableAudioSessionManagement: Bool) {
_disableAudioSessionManagement = disableAudioSessionManagement
}
@objc
func setProgressUpdateInterval(_ progressUpdateInterval: Float) {
_playerObserver.replaceTimeObserverIfSet(Float64(progressUpdateInterval))
+1
View File
@@ -37,6 +37,7 @@ RCT_EXPORT_VIEW_PROPERTY(restoreUserInterfaceForPIPStopCompletionHandler, BOOL);
RCT_EXPORT_VIEW_PROPERTY(localSourceEncryptionKeyScheme, NSString);
RCT_EXPORT_VIEW_PROPERTY(subtitleStyle, NSDictionary);
RCT_EXPORT_VIEW_PROPERTY(showNotificationControls, BOOL);
RCT_EXPORT_VIEW_PROPERTY(disableAudioSessionManagement, BOOL);
/* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */
RCT_EXPORT_VIEW_PROPERTY(onVideoLoadStart, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onVideoLoad, RCTDirectEventBlock);
+1
View File
@@ -369,6 +369,7 @@ export interface VideoNativeProps extends ViewProps {
viewType?: Int32; // Android
bufferingStrategy?: BufferingStrategyType; // Android
controlsStyles?: ControlsStyles; // Android
disableAudioSessionManagement?: boolean; // iOS
onControlsVisibilityChange?: DirectEventHandler<OnControlsVisibilityChange>;
onVideoLoad?: DirectEventHandler<OnLoadData>;
onVideoLoadStart?: DirectEventHandler<OnLoadStartData>;
+1
View File
@@ -350,4 +350,5 @@ export interface ReactVideoProps extends ReactVideoEvents, ViewProps {
debug?: DebugConfig;
allowsExternalPlayback?: boolean; // iOS
controlsStyles?: ControlsStyles; // Android
disableAudioSessionManagement?: boolean; // iOS
}