Skip to content

Commit

Permalink
Merge branch 'master' of github.com:react-native-video/react-native-v…
Browse files Browse the repository at this point in the history
…ideo into feat/addAnalyticsPlugManagement
  • Loading branch information
freeboub committed Jun 22, 2024
2 parents d2b0715 + cfa5984 commit cf3402c
Show file tree
Hide file tree
Showing 10 changed files with 88 additions and 3 deletions.
20 changes: 20 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,25 @@


# [6.3.0](https://github.com/TheWidlarzGroup/react-native-video/compare/v6.2.0...v6.3.0) (2024-06-22)


### Bug Fixes

* **android:** allow chunk less preparation ([#3913](https://github.com/TheWidlarzGroup/react-native-video/issues/3913)) ([264b57a](https://github.com/TheWidlarzGroup/react-native-video/commit/264b57aa2ed01b52c09b2992d5ca61e33871315b))
* **android:** avoid crash multiplayer with notification ([#3931](https://github.com/TheWidlarzGroup/react-native-video/issues/3931)) ([104ee70](https://github.com/TheWidlarzGroup/react-native-video/commit/104ee703bac0f7d5fb162d17c30f65f8071d07a6))
* **android:** show controls in notification on older androids ([#3886](https://github.com/TheWidlarzGroup/react-native-video/issues/3886)) ([098a754](https://github.com/TheWidlarzGroup/react-native-video/commit/098a754110a2c58fc18062769f4dd83775d20de4))
* **android:** use UI thread to pause when lost audio focus ([#3916](https://github.com/TheWidlarzGroup/react-native-video/issues/3916)) ([856b1dd](https://github.com/TheWidlarzGroup/react-native-video/commit/856b1dd58ba9bb1832397ee0fc86f778f737798f))
* **ios:** crash on ads after leaving the app ([#3911](https://github.com/TheWidlarzGroup/react-native-video/issues/3911)) ([3d6bc94](https://github.com/TheWidlarzGroup/react-native-video/commit/3d6bc9409c2111760620a821466b0ea0f1970681))
* **ios:** missing notification controls when enabled from start ([#3898](https://github.com/TheWidlarzGroup/react-native-video/issues/3898)) ([2d793db](https://github.com/TheWidlarzGroup/react-native-video/commit/2d793dbde16cc140d1e7b873c40ff4dec285e253))
* **JS:** safety check on resolve uri ([#3915](https://github.com/TheWidlarzGroup/react-native-video/issues/3915)) ([84bb910](https://github.com/TheWidlarzGroup/react-native-video/commit/84bb910d10e3e3d70f9e92b57c17de829d73218a))
* **typescript:** type checks on selectedTextTrack, selectedAudioTrack, selectedVideoTrack ([#3910](https://github.com/TheWidlarzGroup/react-native-video/issues/3910)) ([dc2a2ab](https://github.com/TheWidlarzGroup/react-native-video/commit/dc2a2ab863dc53fb2da1c2cea99e59e6d8387803))


### Features

* **android:** add `onControlsVisiblityChange` ([#3925](https://github.com/TheWidlarzGroup/react-native-video/issues/3925)) ([c2ce372](https://github.com/TheWidlarzGroup/react-native-video/commit/c2ce372bcf21e21b97878e7efe77780168d09a79))
* **ios:** add live key to now playing dict to decorate when livestream playing ([#3922](https://github.com/TheWidlarzGroup/react-native-video/issues/3922)) ([91751ab](https://github.com/TheWidlarzGroup/react-native-video/commit/91751abc870109e0a2667dfffbd2baa2e4cf997b))

# [6.2.0](https://github.com/TheWidlarzGroup/react-native-video/compare/v6.1.2...v6.2.0) (2024-06-07)


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ public VideoEventEmitter(ReactContext reactContext) {
private static final String EVENT_ERROR = "onVideoError";
private static final String EVENT_PROGRESS = "onVideoProgress";
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_END = "onVideoEnd";
private static final String EVENT_FULLSCREEN_WILL_PRESENT = "onVideoFullscreenPlayerWillPresent";
Expand Down Expand Up @@ -89,6 +90,7 @@ public VideoEventEmitter(ReactContext reactContext) {
EVENT_TEXT_TRACK_DATA_CHANGED,
EVENT_VIDEO_TRACKS,
EVENT_BANDWIDTH,
EVENT_CONTROLS_VISIBILITY_CHANGE,
EVENT_ON_RECEIVE_AD_EVENT
};

Expand Down Expand Up @@ -120,6 +122,7 @@ public VideoEventEmitter(ReactContext reactContext) {
EVENT_TEXT_TRACK_DATA_CHANGED,
EVENT_VIDEO_TRACKS,
EVENT_BANDWIDTH,
EVENT_CONTROLS_VISIBILITY_CHANGE,
EVENT_ON_RECEIVE_AD_EVENT
})
@interface VideoEvents {
Expand Down Expand Up @@ -164,6 +167,8 @@ public VideoEventEmitter(ReactContext reactContext) {

private static final String EVENT_PROP_IS_PLAYING = "isPlaying";

private static final String EVENT_CONTROLS_VISIBLE = "isVisible";

public void setViewId(int viewId) {
this.viewId = viewId;
}
Expand Down Expand Up @@ -354,6 +359,12 @@ public void end() {
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() {
receiveEvent(EVENT_FULLSCREEN_WILL_PRESENT, null);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -420,6 +420,12 @@ private void togglePlayerControlVisibility() {
private void initializePlayerControl() {
if (playerControlView == null) {
playerControlView = new LegacyPlayerControlView(getContext());
playerControlView.addVisibilityListener(new LegacyPlayerControlView.VisibilityListener() {
@Override
public void onVisibilityChange(int visibility) {
eventEmitter.controlsVisibilityChanged(visibility == View.VISIBLE);
}
});
}

if (fullScreenPlayerView == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,6 @@ class VideoPlaybackService : MediaSessionService() {
hidePlayerNotification(player)
val session = mediaSessionsList.remove(player)
session?.release()
sourceActivity = null

if (mediaSessionsList.isEmpty()) {
cleanup()
stopSelf()
Expand Down
20 changes: 20 additions & 0 deletions docs/pages/component/events.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -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`

<PlatformsList types={['All']} />
Expand Down
11 changes: 11 additions & 0 deletions ios/Video/NowPlayingInfoCenterManager.swift
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,12 @@ class NowPlayingInfoCenterManager {
})
}

if CMTIME_IS_INDEFINITE(currentItem.asset.duration) {
nowPlayingInfo[MPNowPlayingInfoPropertyIsLiveStream] = true
} else {
nowPlayingInfo[MPNowPlayingInfoPropertyIsLiveStream] = false
}

nowPlayingInfo[MPMediaItemPropertyPlaybackDuration] = currentItem.duration.seconds
nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = currentItem.currentTime().seconds
nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = player.rate
Expand All @@ -245,6 +251,11 @@ class NowPlayingInfoCenterManager {
nowPlayingInfo[MPNowPlayingInfoPropertyElapsedPlaybackTime] = currentItem.currentTime().seconds.rounded()
nowPlayingInfo[MPNowPlayingInfoPropertyPlaybackRate] = player.rate

if CMTIME_IS_INDEFINITE(currentItem.asset.duration) {
nowPlayingInfo[MPNowPlayingInfoPropertyIsLiveStream] = true
} else {
nowPlayingInfo[MPNowPlayingInfoPropertyIsLiveStream] = false
}
MPNowPlayingInfoCenter.default().nowPlayingInfo = nowPlayingInfo
}
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "react-native-video",
"version": "6.2.0",
"version": "6.3.0",
"description": "A <Video /> element for react-native",
"main": "lib/index",
"source": "src/index",
Expand Down
12 changes: 12 additions & 0 deletions src/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import NativeVideoComponent, {
type OnAudioTracksData,
type OnBandwidthUpdateData,
type OnBufferData,
type OnControlsVisibilityChange,
type OnExternalPlaybackChangeData,
type OnGetLicenseData,
type OnLoadStartData,
Expand Down Expand Up @@ -91,6 +92,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
onEnd,
onBuffer,
onBandwidthUpdate,
onControlsVisibilityChange,
onExternalPlaybackChange,
onFullscreenPlayerWillPresent,
onFullscreenPlayerDidPresent,
Expand Down Expand Up @@ -482,6 +484,13 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
[onAspectRatio],
);

const _onControlsVisibilityChange = useCallback(
(e: NativeSyntheticEvent<OnControlsVisibilityChange>) => {
onControlsVisibilityChange?.(e.nativeEvent);
},
[onControlsVisibilityChange],
);

const useExternalGetLicense = drm?.getLicense instanceof Function;

const onGetLicense = useCallback(
Expand Down Expand Up @@ -639,6 +648,9 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
? (_onReceiveAdEvent as (e: NativeSyntheticEvent<object>) => void)
: undefined
}
onControlsVisibilityChange={
onControlsVisibilityChange ? _onControlsVisibilityChange : undefined
}
/>
{hasPoster && showPoster ? (
<Image style={posterStyle} source={{uri: poster}} />
Expand Down
5 changes: 5 additions & 0 deletions src/specs/VideoNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,6 +289,10 @@ type ControlsStyles = Readonly<{
seekIncrementMS?: number;
}>;

export type OnControlsVisibilityChange = Readonly<{
isVisible: boolean;
}>;

export interface VideoNativeProps extends ViewProps {
src?: VideoSrc;
drm?: Drm;
Expand Down Expand Up @@ -337,6 +341,7 @@ export interface VideoNativeProps extends ViewProps {
useSecureView?: boolean; // Android
bufferingStrategy?: BufferingStrategyType; // Android
controlsStyles?: ControlsStyles; // Android
onControlsVisibilityChange?: DirectEventHandler<OnControlsVisibilityChange>;
onVideoLoad?: DirectEventHandler<OnLoadData>;
onVideoLoadStart?: DirectEventHandler<OnLoadStartData>;
onVideoAspectRatio?: DirectEventHandler<OnVideoAspectRatioData>;
Expand Down
2 changes: 2 additions & 0 deletions src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import type {
OnAudioTracksData,
OnBandwidthUpdateData,
OnBufferData,
OnControlsVisibilityChange,
OnExternalPlaybackChangeData,
OnLoadStartData,
OnPictureInPictureStatusChangedData,
Expand Down Expand Up @@ -237,6 +238,7 @@ export interface ReactVideoEvents {
onIdle?: () => void; // Android
onBandwidthUpdate?: (e: OnBandwidthUpdateData) => void; //Android
onBuffer?: (e: OnBufferData) => void; //Android, iOS
onControlsVisibilityChange?: (e: OnControlsVisibilityChange) => void; // Android, iOS
onEnd?: () => void; //All
onError?: (e: OnVideoErrorData) => void; //Android, iOS
onExternalPlaybackChange?: (e: OnExternalPlaybackChangeData) => void; //iOS
Expand Down

0 comments on commit cf3402c

Please sign in to comment.