diff --git a/docs/pages/component/props.mdx b/docs/pages/component/props.mdx index e85d38c8..a91c9757 100644 --- a/docs/pages/component/props.mdx +++ b/docs/pages/component/props.mdx @@ -271,6 +271,20 @@ Determines if the player should throw an error when the network connection is lo --- +### `disableAudioSessionManagement` + + + +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] diff --git a/ios/Video/AudioSessionManager.swift b/ios/Video/AudioSessionManager.swift index 5dc43ec5..c9fa362e 100644 --- a/ios/Video/AudioSessionManager.swift +++ b/ios/Video/AudioSessionManager.swift @@ -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" diff --git a/ios/Video/RCTVideo.swift b/ios/Video/RCTVideo.swift index fbf24137..f029ea05 100644 --- a/ios/Video/RCTVideo.swift +++ b/ios/Video/RCTVideo.swift @@ -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)) diff --git a/ios/Video/RCTVideoManager.m b/ios/Video/RCTVideoManager.m index 330aef85..2d7cd363 100644 --- a/ios/Video/RCTVideoManager.m +++ b/ios/Video/RCTVideoManager.m @@ -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); diff --git a/src/specs/VideoNativeComponent.ts b/src/specs/VideoNativeComponent.ts index 69412bc8..493736d9 100644 --- a/src/specs/VideoNativeComponent.ts +++ b/src/specs/VideoNativeComponent.ts @@ -369,6 +369,7 @@ export interface VideoNativeProps extends ViewProps { viewType?: Int32; // Android bufferingStrategy?: BufferingStrategyType; // Android controlsStyles?: ControlsStyles; // Android + disableAudioSessionManagement?: boolean; // iOS onControlsVisibilityChange?: DirectEventHandler; onVideoLoad?: DirectEventHandler; onVideoLoadStart?: DirectEventHandler; diff --git a/src/types/video.ts b/src/types/video.ts index 1be6775e..82861bd6 100644 --- a/src/types/video.ts +++ b/src/types/video.ts @@ -350,4 +350,5 @@ export interface ReactVideoProps extends ReactVideoEvents, ViewProps { debug?: DebugConfig; allowsExternalPlayback?: boolean; // iOS controlsStyles?: ControlsStyles; // Android + disableAudioSessionManagement?: boolean; // iOS }