mirror of
https://github.com/zoriya/react-native-video.git
synced 2026-05-31 18:24:59 +00:00
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:
@@ -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]
|
||||
|
||||
@@ -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"
|
||||
|
||||
@@ -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))
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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>;
|
||||
|
||||
@@ -350,4 +350,5 @@ export interface ReactVideoProps extends ReactVideoEvents, ViewProps {
|
||||
debug?: DebugConfig;
|
||||
allowsExternalPlayback?: boolean; // iOS
|
||||
controlsStyles?: ControlsStyles; // Android
|
||||
disableAudioSessionManagement?: boolean; // iOS
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user