mirror of
https://github.com/zoriya/react-native-video.git
synced 2026-06-09 21:36:31 +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`
|
### `drm`
|
||||||
|
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
@@ -1183,6 +1197,7 @@ To customize the notification controls, you can use the `metadata` property in t
|
|||||||
```
|
```
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
### `useSecureView`
|
### `useSecureView`
|
||||||
|
|
||||||
> [!WARNING]
|
> [!WARNING]
|
||||||
|
|||||||
@@ -8,6 +8,12 @@ class AudioSessionManager {
|
|||||||
private var isAudioSessionActive = false
|
private var isAudioSessionActive = false
|
||||||
private var remoteControlEventsActive = false
|
private var remoteControlEventsActive = false
|
||||||
|
|
||||||
|
private var isAudioSessionManagementDisabled: Bool {
|
||||||
|
return videoViews.allObjects.contains { view in
|
||||||
|
return view._disableAudioSessionManagement == true
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private init() {
|
private init() {
|
||||||
// Subscribe to audio interruption notifications
|
// Subscribe to audio interruption notifications
|
||||||
NotificationCenter.default.addObserver(
|
NotificationCenter.default.addObserver(
|
||||||
@@ -69,6 +75,11 @@ class AudioSessionManager {
|
|||||||
|
|
||||||
// Handle remote control events from NowPlayingInfoCenterManager
|
// Handle remote control events from NowPlayingInfoCenterManager
|
||||||
func setRemoteControlEventsActive(_ active: Bool) {
|
func setRemoteControlEventsActive(_ active: Bool) {
|
||||||
|
if isAudioSessionManagementDisabled {
|
||||||
|
// AUDIO SESSION MANAGEMENT DISABLED BY USER
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
remoteControlEventsActive = active
|
remoteControlEventsActive = active
|
||||||
|
|
||||||
if active {
|
if active {
|
||||||
@@ -130,6 +141,11 @@ class AudioSessionManager {
|
|||||||
|
|
||||||
let canAllowMixing = !anyPlayerShowNotificationControls && !anyPlayerNeedsBackgroundPlayback
|
let canAllowMixing = !anyPlayerShowNotificationControls && !anyPlayerNeedsBackgroundPlayback
|
||||||
|
|
||||||
|
if isAudioSessionManagementDisabled {
|
||||||
|
// AUDIO SESSION MANAGEMENT DISABLED BY USER
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if canAllowMixing {
|
if canAllowMixing {
|
||||||
let shouldEnableMixing = videoViews.allObjects.contains { view in
|
let shouldEnableMixing = videoViews.allObjects.contains { view in
|
||||||
return view._mixWithOthers == "mix"
|
return view._mixWithOthers == "mix"
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
private var _filterEnabled = false
|
private var _filterEnabled = false
|
||||||
private var _presentingViewController: UIViewController?
|
private var _presentingViewController: UIViewController?
|
||||||
private var _startPosition: Float64 = -1
|
private var _startPosition: Float64 = -1
|
||||||
|
var _disableAudioSessionManagement: Bool = false
|
||||||
var _showNotificationControls = false
|
var _showNotificationControls = false
|
||||||
// Buffer last bitrate value received. Initialized to -2 to ensure -1 (sometimes reported by AVPlayer) is not missed
|
// Buffer last bitrate value received. Initialized to -2 to ensure -1 (sometimes reported by AVPlayer) is not missed
|
||||||
private var _lastBitrate = -2.0
|
private var _lastBitrate = -2.0
|
||||||
@@ -1233,6 +1234,11 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc
|
||||||
|
func setDisableAudioSessionManagement(_ disableAudioSessionManagement: Bool) {
|
||||||
|
_disableAudioSessionManagement = disableAudioSessionManagement
|
||||||
|
}
|
||||||
|
|
||||||
@objc
|
@objc
|
||||||
func setProgressUpdateInterval(_ progressUpdateInterval: Float) {
|
func setProgressUpdateInterval(_ progressUpdateInterval: Float) {
|
||||||
_playerObserver.replaceTimeObserverIfSet(Float64(progressUpdateInterval))
|
_playerObserver.replaceTimeObserverIfSet(Float64(progressUpdateInterval))
|
||||||
|
|||||||
@@ -37,6 +37,7 @@ RCT_EXPORT_VIEW_PROPERTY(restoreUserInterfaceForPIPStopCompletionHandler, BOOL);
|
|||||||
RCT_EXPORT_VIEW_PROPERTY(localSourceEncryptionKeyScheme, NSString);
|
RCT_EXPORT_VIEW_PROPERTY(localSourceEncryptionKeyScheme, NSString);
|
||||||
RCT_EXPORT_VIEW_PROPERTY(subtitleStyle, NSDictionary);
|
RCT_EXPORT_VIEW_PROPERTY(subtitleStyle, NSDictionary);
|
||||||
RCT_EXPORT_VIEW_PROPERTY(showNotificationControls, BOOL);
|
RCT_EXPORT_VIEW_PROPERTY(showNotificationControls, BOOL);
|
||||||
|
RCT_EXPORT_VIEW_PROPERTY(disableAudioSessionManagement, BOOL);
|
||||||
/* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */
|
/* Should support: onLoadStart, onLoad, and onError to stay consistent with Image */
|
||||||
RCT_EXPORT_VIEW_PROPERTY(onVideoLoadStart, RCTDirectEventBlock);
|
RCT_EXPORT_VIEW_PROPERTY(onVideoLoadStart, RCTDirectEventBlock);
|
||||||
RCT_EXPORT_VIEW_PROPERTY(onVideoLoad, RCTDirectEventBlock);
|
RCT_EXPORT_VIEW_PROPERTY(onVideoLoad, RCTDirectEventBlock);
|
||||||
|
|||||||
@@ -369,6 +369,7 @@ export interface VideoNativeProps extends ViewProps {
|
|||||||
viewType?: Int32; // Android
|
viewType?: Int32; // Android
|
||||||
bufferingStrategy?: BufferingStrategyType; // Android
|
bufferingStrategy?: BufferingStrategyType; // Android
|
||||||
controlsStyles?: ControlsStyles; // Android
|
controlsStyles?: ControlsStyles; // Android
|
||||||
|
disableAudioSessionManagement?: boolean; // iOS
|
||||||
onControlsVisibilityChange?: DirectEventHandler<OnControlsVisibilityChange>;
|
onControlsVisibilityChange?: DirectEventHandler<OnControlsVisibilityChange>;
|
||||||
onVideoLoad?: DirectEventHandler<OnLoadData>;
|
onVideoLoad?: DirectEventHandler<OnLoadData>;
|
||||||
onVideoLoadStart?: DirectEventHandler<OnLoadStartData>;
|
onVideoLoadStart?: DirectEventHandler<OnLoadStartData>;
|
||||||
|
|||||||
@@ -350,4 +350,5 @@ export interface ReactVideoProps extends ReactVideoEvents, ViewProps {
|
|||||||
debug?: DebugConfig;
|
debug?: DebugConfig;
|
||||||
allowsExternalPlayback?: boolean; // iOS
|
allowsExternalPlayback?: boolean; // iOS
|
||||||
controlsStyles?: ControlsStyles; // Android
|
controlsStyles?: ControlsStyles; // Android
|
||||||
|
disableAudioSessionManagement?: boolean; // iOS
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user