feat: add setVolume function to component's ref (#3794)
* feat: add setVolume function to component's ref * Update methods.mdx
This commit is contained in:
parent
d4c9be2ba0
commit
3cd7ab60b2
@ -54,6 +54,13 @@ class VideoManagerModule(reactContext: ReactApplicationContext?) : ReactContextB
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ReactMethod
|
||||||
|
fun setVolume(volume: Float, reactTag: Int) {
|
||||||
|
performOnPlayerView(reactTag) {
|
||||||
|
it?.setVolumeModifier(volume)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
private const val REACT_CLASS = "VideoManager"
|
private const val REACT_CLASS = "VideoManager"
|
||||||
}
|
}
|
||||||
|
@ -92,6 +92,14 @@ By default iOS seeks within 100 milliseconds of the target position. If you need
|
|||||||
|
|
||||||
tolerance is the max distance in milliseconds from the seconds position that's allowed. Using a more exact tolerance can cause seeks to take longer. If you want to seek exactly, set tolerance to 0.
|
tolerance is the max distance in milliseconds from the seconds position that's allowed. Using a more exact tolerance can cause seeks to take longer. If you want to seek exactly, set tolerance to 0.
|
||||||
|
|
||||||
|
### `setVolume`
|
||||||
|
|
||||||
|
<PlatformsList types={['Android', 'iOS']} />
|
||||||
|
|
||||||
|
`setVolume(value): Promise<void>`
|
||||||
|
|
||||||
|
This function will change the volume exactly like [volume](../props#volume) property. default value and range are the same then.
|
||||||
|
|
||||||
### Example Usage
|
### Example Usage
|
||||||
|
|
||||||
```tsx
|
```tsx
|
||||||
|
@ -86,4 +86,6 @@ RCT_EXTERN_METHOD(presentFullscreenPlayer : (nonnull NSNumber*)reactTag)
|
|||||||
|
|
||||||
RCT_EXTERN_METHOD(dismissFullscreenPlayer : (nonnull NSNumber*)reactTag)
|
RCT_EXTERN_METHOD(dismissFullscreenPlayer : (nonnull NSNumber*)reactTag)
|
||||||
|
|
||||||
|
RCT_EXTERN_METHOD(setVolume : (nonnull float*)volume reactTag : (nonnull NSNumber*)reactTag)
|
||||||
|
|
||||||
@end
|
@end
|
||||||
|
@ -77,6 +77,13 @@ class RCTVideoManager: RCTViewManager {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@objc(setVolume:reactTag:)
|
||||||
|
func setVolume(value: Float, reactTag: NSNumber) {
|
||||||
|
performOnVideoView(withReactTag: reactTag, callback: { videoView in
|
||||||
|
videoView?.setVolume(value)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
override class func requiresMainQueueSetup() -> Bool {
|
override class func requiresMainQueueSetup() -> Bool {
|
||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
|
@ -64,6 +64,7 @@ export interface VideoRef {
|
|||||||
restore: boolean,
|
restore: boolean,
|
||||||
) => void;
|
) => void;
|
||||||
save: (options: object) => Promise<VideoSaveData>;
|
save: (options: object) => Promise<VideoSaveData>;
|
||||||
|
setVolume: (volume: number) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
const Video = forwardRef<VideoRef, ReactVideoProps>(
|
const Video = forwardRef<VideoRef, ReactVideoProps>(
|
||||||
@ -289,6 +290,10 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
[setRestoreUserInterfaceForPIPStopCompletionHandler],
|
[setRestoreUserInterfaceForPIPStopCompletionHandler],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const setVolume = useCallback((volume: number) => {
|
||||||
|
return VideoManager.setVolume(volume, getReactTag(nativeRef));
|
||||||
|
}, []);
|
||||||
|
|
||||||
const onVideoLoadStart = useCallback(
|
const onVideoLoadStart = useCallback(
|
||||||
(e: NativeSyntheticEvent<OnLoadStartData>) => {
|
(e: NativeSyntheticEvent<OnLoadStartData>) => {
|
||||||
hasPoster && setShowPoster(true);
|
hasPoster && setShowPoster(true);
|
||||||
@ -505,6 +510,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
pause,
|
pause,
|
||||||
resume,
|
resume,
|
||||||
restoreUserInterfaceForPictureInPictureStopCompleted,
|
restoreUserInterfaceForPictureInPictureStopCompleted,
|
||||||
|
setVolume,
|
||||||
}),
|
}),
|
||||||
[
|
[
|
||||||
seek,
|
seek,
|
||||||
@ -514,6 +520,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
pause,
|
pause,
|
||||||
resume,
|
resume,
|
||||||
restoreUserInterfaceForPictureInPictureStopCompleted,
|
restoreUserInterfaceForPictureInPictureStopCompleted,
|
||||||
|
setVolume,
|
||||||
],
|
],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -372,6 +372,7 @@ export interface VideoManagerType {
|
|||||||
licenseUrl: string,
|
licenseUrl: string,
|
||||||
reactTag: number,
|
reactTag: number,
|
||||||
) => Promise<void>;
|
) => Promise<void>;
|
||||||
|
setVolume: (volume: number, reactTag: number) => Promise<void>;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface VideoDecoderPropertiesType {
|
export interface VideoDecoderPropertiesType {
|
||||||
|
Loading…
Reference in New Issue
Block a user