feat(android): add onControlsVisiblityChange
(#3925)
* Adding onControlsVisiblityChange for Android
This commit is contained in:
parent
104ee703ba
commit
c2ce372bcf
@ -37,6 +37,7 @@ public class VideoEventEmitter {
|
|||||||
private static final String EVENT_ERROR = "onVideoError";
|
private static final String EVENT_ERROR = "onVideoError";
|
||||||
private static final String EVENT_PROGRESS = "onVideoProgress";
|
private static final String EVENT_PROGRESS = "onVideoProgress";
|
||||||
private static final String EVENT_BANDWIDTH = "onVideoBandwidthUpdate";
|
private static final String EVENT_BANDWIDTH = "onVideoBandwidthUpdate";
|
||||||
|
private static final String EVENT_CONTROLS_VISIBILITY_CHANGE = "onControlsVisibilityChange";
|
||||||
private static final String EVENT_SEEK = "onVideoSeek";
|
private static final String EVENT_SEEK = "onVideoSeek";
|
||||||
private static final String EVENT_END = "onVideoEnd";
|
private static final String EVENT_END = "onVideoEnd";
|
||||||
private static final String EVENT_FULLSCREEN_WILL_PRESENT = "onVideoFullscreenPlayerWillPresent";
|
private static final String EVENT_FULLSCREEN_WILL_PRESENT = "onVideoFullscreenPlayerWillPresent";
|
||||||
@ -89,6 +90,7 @@ public class VideoEventEmitter {
|
|||||||
EVENT_TEXT_TRACK_DATA_CHANGED,
|
EVENT_TEXT_TRACK_DATA_CHANGED,
|
||||||
EVENT_VIDEO_TRACKS,
|
EVENT_VIDEO_TRACKS,
|
||||||
EVENT_BANDWIDTH,
|
EVENT_BANDWIDTH,
|
||||||
|
EVENT_CONTROLS_VISIBILITY_CHANGE,
|
||||||
EVENT_ON_RECEIVE_AD_EVENT
|
EVENT_ON_RECEIVE_AD_EVENT
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -120,6 +122,7 @@ public class VideoEventEmitter {
|
|||||||
EVENT_TEXT_TRACK_DATA_CHANGED,
|
EVENT_TEXT_TRACK_DATA_CHANGED,
|
||||||
EVENT_VIDEO_TRACKS,
|
EVENT_VIDEO_TRACKS,
|
||||||
EVENT_BANDWIDTH,
|
EVENT_BANDWIDTH,
|
||||||
|
EVENT_CONTROLS_VISIBILITY_CHANGE,
|
||||||
EVENT_ON_RECEIVE_AD_EVENT
|
EVENT_ON_RECEIVE_AD_EVENT
|
||||||
})
|
})
|
||||||
@interface VideoEvents {
|
@interface VideoEvents {
|
||||||
@ -164,6 +167,8 @@ public class VideoEventEmitter {
|
|||||||
|
|
||||||
private static final String EVENT_PROP_IS_PLAYING = "isPlaying";
|
private static final String EVENT_PROP_IS_PLAYING = "isPlaying";
|
||||||
|
|
||||||
|
private static final String EVENT_CONTROLS_VISIBLE = "isVisible";
|
||||||
|
|
||||||
public void setViewId(int viewId) {
|
public void setViewId(int viewId) {
|
||||||
this.viewId = viewId;
|
this.viewId = viewId;
|
||||||
}
|
}
|
||||||
@ -354,6 +359,12 @@ public class VideoEventEmitter {
|
|||||||
receiveEvent(EVENT_END, null);
|
receiveEvent(EVENT_END, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void controlsVisibilityChanged(boolean isVisible) {
|
||||||
|
WritableMap map = Arguments.createMap();
|
||||||
|
map.putBoolean(EVENT_CONTROLS_VISIBLE, isVisible);
|
||||||
|
receiveEvent(EVENT_CONTROLS_VISIBILITY_CHANGE, map);
|
||||||
|
}
|
||||||
|
|
||||||
public void fullscreenWillPresent() {
|
public void fullscreenWillPresent() {
|
||||||
receiveEvent(EVENT_FULLSCREEN_WILL_PRESENT, null);
|
receiveEvent(EVENT_FULLSCREEN_WILL_PRESENT, null);
|
||||||
}
|
}
|
||||||
|
@ -416,6 +416,12 @@ public class ReactExoplayerView extends FrameLayout implements
|
|||||||
private void initializePlayerControl() {
|
private void initializePlayerControl() {
|
||||||
if (playerControlView == null) {
|
if (playerControlView == null) {
|
||||||
playerControlView = new LegacyPlayerControlView(getContext());
|
playerControlView = new LegacyPlayerControlView(getContext());
|
||||||
|
playerControlView.addVisibilityListener(new LegacyPlayerControlView.VisibilityListener() {
|
||||||
|
@Override
|
||||||
|
public void onVisibilityChange(int visibility) {
|
||||||
|
eventEmitter.controlsVisibilityChanged(visibility == View.VISIBLE);
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
if (fullScreenPlayerView == null) {
|
if (fullScreenPlayerView == null) {
|
||||||
|
@ -121,6 +121,26 @@ Example:
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
### `onControlsVisibilityChange`
|
||||||
|
|
||||||
|
<PlatformsList types={['Android']} />
|
||||||
|
|
||||||
|
Callback function that is called when the controls are hidden or shown. Not possible on iOS.
|
||||||
|
|
||||||
|
Payload:
|
||||||
|
|
||||||
|
| Property | Type | Description |
|
||||||
|
| ----------- | ------- | ---------------------------------------------- |
|
||||||
|
| isVisible | boolean | Boolean indicating whether controls are visible |
|
||||||
|
|
||||||
|
Example:
|
||||||
|
|
||||||
|
```javascript
|
||||||
|
{
|
||||||
|
isVisible: true;
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
### `onEnd`
|
### `onEnd`
|
||||||
|
|
||||||
<PlatformsList types={['All']} />
|
<PlatformsList types={['All']} />
|
||||||
|
@ -22,6 +22,7 @@ import NativeVideoComponent, {
|
|||||||
type OnAudioTracksData,
|
type OnAudioTracksData,
|
||||||
type OnBandwidthUpdateData,
|
type OnBandwidthUpdateData,
|
||||||
type OnBufferData,
|
type OnBufferData,
|
||||||
|
type OnControlsVisibilityChange,
|
||||||
type OnExternalPlaybackChangeData,
|
type OnExternalPlaybackChangeData,
|
||||||
type OnGetLicenseData,
|
type OnGetLicenseData,
|
||||||
type OnLoadStartData,
|
type OnLoadStartData,
|
||||||
@ -91,6 +92,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
onEnd,
|
onEnd,
|
||||||
onBuffer,
|
onBuffer,
|
||||||
onBandwidthUpdate,
|
onBandwidthUpdate,
|
||||||
|
onControlsVisibilityChange,
|
||||||
onExternalPlaybackChange,
|
onExternalPlaybackChange,
|
||||||
onFullscreenPlayerWillPresent,
|
onFullscreenPlayerWillPresent,
|
||||||
onFullscreenPlayerDidPresent,
|
onFullscreenPlayerDidPresent,
|
||||||
@ -482,6 +484,13 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
[onAspectRatio],
|
[onAspectRatio],
|
||||||
);
|
);
|
||||||
|
|
||||||
|
const _onControlsVisibilityChange = useCallback(
|
||||||
|
(e: NativeSyntheticEvent<OnControlsVisibilityChange>) => {
|
||||||
|
onControlsVisibilityChange?.(e.nativeEvent);
|
||||||
|
},
|
||||||
|
[onControlsVisibilityChange],
|
||||||
|
);
|
||||||
|
|
||||||
const useExternalGetLicense = drm?.getLicense instanceof Function;
|
const useExternalGetLicense = drm?.getLicense instanceof Function;
|
||||||
|
|
||||||
const onGetLicense = useCallback(
|
const onGetLicense = useCallback(
|
||||||
@ -639,6 +648,9 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
|
|||||||
? (_onReceiveAdEvent as (e: NativeSyntheticEvent<object>) => void)
|
? (_onReceiveAdEvent as (e: NativeSyntheticEvent<object>) => void)
|
||||||
: undefined
|
: undefined
|
||||||
}
|
}
|
||||||
|
onControlsVisibilityChange={
|
||||||
|
onControlsVisibilityChange ? _onControlsVisibilityChange : undefined
|
||||||
|
}
|
||||||
/>
|
/>
|
||||||
{hasPoster && showPoster ? (
|
{hasPoster && showPoster ? (
|
||||||
<Image style={posterStyle} source={{uri: poster}} />
|
<Image style={posterStyle} source={{uri: poster}} />
|
||||||
|
@ -289,6 +289,10 @@ type ControlsStyles = Readonly<{
|
|||||||
seekIncrementMS?: number;
|
seekIncrementMS?: number;
|
||||||
}>;
|
}>;
|
||||||
|
|
||||||
|
export type OnControlsVisibilityChange = Readonly<{
|
||||||
|
isVisible: boolean;
|
||||||
|
}>;
|
||||||
|
|
||||||
export interface VideoNativeProps extends ViewProps {
|
export interface VideoNativeProps extends ViewProps {
|
||||||
src?: VideoSrc;
|
src?: VideoSrc;
|
||||||
drm?: Drm;
|
drm?: Drm;
|
||||||
@ -337,6 +341,7 @@ export interface VideoNativeProps extends ViewProps {
|
|||||||
useSecureView?: boolean; // Android
|
useSecureView?: boolean; // Android
|
||||||
bufferingStrategy?: BufferingStrategyType; // Android
|
bufferingStrategy?: BufferingStrategyType; // Android
|
||||||
controlsStyles?: ControlsStyles; // Android
|
controlsStyles?: ControlsStyles; // Android
|
||||||
|
onControlsVisibilityChange?: DirectEventHandler<OnControlsVisibilityChange>;
|
||||||
onVideoLoad?: DirectEventHandler<OnLoadData>;
|
onVideoLoad?: DirectEventHandler<OnLoadData>;
|
||||||
onVideoLoadStart?: DirectEventHandler<OnLoadStartData>;
|
onVideoLoadStart?: DirectEventHandler<OnLoadStartData>;
|
||||||
onVideoAspectRatio?: DirectEventHandler<OnVideoAspectRatioData>;
|
onVideoAspectRatio?: DirectEventHandler<OnVideoAspectRatioData>;
|
||||||
|
@ -4,6 +4,7 @@ import type {
|
|||||||
OnAudioTracksData,
|
OnAudioTracksData,
|
||||||
OnBandwidthUpdateData,
|
OnBandwidthUpdateData,
|
||||||
OnBufferData,
|
OnBufferData,
|
||||||
|
OnControlsVisibilityChange,
|
||||||
OnExternalPlaybackChangeData,
|
OnExternalPlaybackChangeData,
|
||||||
OnLoadStartData,
|
OnLoadStartData,
|
||||||
OnPictureInPictureStatusChangedData,
|
OnPictureInPictureStatusChangedData,
|
||||||
@ -237,6 +238,7 @@ export interface ReactVideoEvents {
|
|||||||
onIdle?: () => void; // Android
|
onIdle?: () => void; // Android
|
||||||
onBandwidthUpdate?: (e: OnBandwidthUpdateData) => void; //Android
|
onBandwidthUpdate?: (e: OnBandwidthUpdateData) => void; //Android
|
||||||
onBuffer?: (e: OnBufferData) => void; //Android, iOS
|
onBuffer?: (e: OnBufferData) => void; //Android, iOS
|
||||||
|
onControlsVisibilityChange?: (e: OnControlsVisibilityChange) => void; // Android, iOS
|
||||||
onEnd?: () => void; //All
|
onEnd?: () => void; //All
|
||||||
onError?: (e: OnVideoErrorData) => void; //Android, iOS
|
onError?: (e: OnVideoErrorData) => void; //Android, iOS
|
||||||
onExternalPlaybackChange?: (e: OnExternalPlaybackChangeData) => void; //iOS
|
onExternalPlaybackChange?: (e: OnExternalPlaybackChangeData) => void; //iOS
|
||||||
|
Loading…
Reference in New Issue
Block a user