Skip to content

Commit

Permalink
feat: rename onSubtitleTracks to onTextTrackDataChanged
Browse files Browse the repository at this point in the history
Renamed the onSubtitleTracks event to onTextTrackDataChanged across the codebase to clearly indicate the callback's purpose: being called when the text track's data changes. This change is reflected in the events documentation, example usage in VideoPlayer.tsx, and the relevant iOS implementation files for consistency and clarity, in line with PR feedback.
  • Loading branch information
coofzilla committed Feb 26, 2024
1 parent a53885f commit fd76dd9
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 20 deletions.
4 changes: 2 additions & 2 deletions docs/pages/component/events.md
Original file line number Diff line number Diff line change
Expand Up @@ -493,8 +493,8 @@ Example:
}
```

### `onSubtitleTracks`
Callback function that is called when subtitles are available. This provides the actual subtitle content.
### `onTextTrackDataChanged`
Callback function that is called when new subtitle data is available. It provides the actual subtitle content for the current selected text track, if available (mainly WebVTT).

Payload:

Expand Down
8 changes: 4 additions & 4 deletions examples/basic/src/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import Video, {
ResizeMode,
SelectedTrack,
DRMType,
OnSubtitleTracksData,
OnTextTrackDataChangedData,
SelectedTrackType,
} from 'react-native-video';
import ToggleControl from './ToggleControl';
Expand Down Expand Up @@ -124,7 +124,7 @@ class VideoPlayer extends Component {

srcIosList = [
{
description: 'example to get subtitles',
description: 'sintel with subtitles',
uri: 'https://bitmovin-a.akamaihd.net/content/sintel/hls/playlist.m3u8',
},
];
Expand Down Expand Up @@ -255,7 +255,7 @@ class VideoPlayer extends Component {
}
};

onSubtitleTracks = (data: OnSubtitleTracksData) => {
onTextTrackDataChanged = (data: OnTextTrackDataChangedData) => {
console.log(`Subtitles: ${JSON.stringify(data, null, 2)}`);
};

Expand Down Expand Up @@ -760,7 +760,7 @@ class VideoPlayer extends Component {
onLoad={this.onLoad}
onAudioTracks={this.onAudioTracks}
onTextTracks={this.onTextTracks}
onSubtitleTracks={this.onSubtitleTracks}
onTextTrackDataChanged={this.onTextTrackDataChanged}
onProgress={this.onProgress}
onEnd={this.onEnd}
progressUpdateInterval={1000}
Expand Down
4 changes: 2 additions & 2 deletions ios/Video/RCTVideo.swift
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH
@objc var onReceiveAdEvent: RCTDirectEventBlock?
@objc var onTextTracks: RCTDirectEventBlock?
@objc var onAudioTracks: RCTDirectEventBlock?
@objc var onSubtitleTracks: RCTDirectEventBlock?
@objc var onTextTrackDataChanged: RCTDirectEventBlock?

@objc
func _onPictureInPictureStatusChanged() {
Expand Down Expand Up @@ -1390,7 +1390,7 @@ class RCTVideo: UIView, RCTVideoPlayerViewControllerDelegate, RCTPlayerObserverH

func handleLegibleOutput(strings: [NSAttributedString]) {
if let subtitles = strings.first {
self.onSubtitleTracks?(["subtitleTracks": subtitles.string])
self.onTextTrackDataChanged?(["subtitleTracks": subtitles.string])
}
}
}
2 changes: 1 addition & 1 deletion ios/Video/RCTVideoManager.m
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ @interface RCT_EXTERN_MODULE (RCTVideoManager, RCTViewManager)
RCT_EXPORT_VIEW_PROPERTY(onReceiveAdEvent, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onTextTracks, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onAudioTracks, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onSubtitleTracks, RCTDirectEventBlock);
RCT_EXPORT_VIEW_PROPERTY(onTextTrackDataChanged, RCTDirectEventBlock);

RCT_EXTERN_METHOD(save
: (NSDictionary*)options reactTag
Expand Down
14 changes: 7 additions & 7 deletions src/Video.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import type {
OnProgressData,
OnReceiveAdEventData,
OnSeekData,
OnSubtitleTracksData,
OnTextTrackDataChangedData,
OnTextTracksData,
OnTimedMetadataData,
OnVideoAspectRatioData,
Expand Down Expand Up @@ -94,7 +94,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
onTimedMetadata,
onAudioTracks,
onTextTracks,
onSubtitleTracks,
onTextTrackDataChanged,
onVideoTracks,
onAspectRatio,
...rest
Expand Down Expand Up @@ -335,11 +335,11 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
[onTextTracks],
);

const _onSubtitleTracks = useCallback(
(e: NativeSyntheticEvent<OnSubtitleTracksData>) => {
onSubtitleTracks?.(e.nativeEvent);
const _onTextTrackDataChanged = useCallback(
(e: NativeSyntheticEvent<OnTextTrackDataChangedData>) => {
onTextTrackDataChanged?.(e.nativeEvent);
},
[onSubtitleTracks],
[onTextTrackDataChanged],
);

const _onVideoTracks = useCallback(
Expand Down Expand Up @@ -518,7 +518,7 @@ const Video = forwardRef<VideoRef, ReactVideoProps>(
onTimedMetadata={_onTimedMetadata}
onAudioTracks={_onAudioTracks}
onTextTracks={_onTextTracks}
onSubtitleTracks={_onSubtitleTracks}
onTextTrackDataChanged={_onTextTrackDataChanged}
onVideoTracks={_onVideoTracks}
onVideoFullscreenPlayerDidDismiss={onFullscreenPlayerDidDismiss}
onVideoFullscreenPlayerDidPresent={onFullscreenPlayerDidPresent}
Expand Down
6 changes: 4 additions & 2 deletions src/VideoNativeComponent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import type Orientation from './types/Orientation';
import type {
AdEvent,
EnumValues,
OnSubtitleTracksData,
OnTextTrackDataChangedData,
OnTextTracksTypeData,
} from './types';

Expand Down Expand Up @@ -371,7 +371,9 @@ export interface VideoNativeProps extends ViewProps {
onTimedMetadata?: (event: NativeSyntheticEvent<OnTimedMetadataData>) => void; // ios, android
onAudioTracks?: (event: NativeSyntheticEvent<OnAudioTracksData>) => void; // android
onTextTracks?: (event: NativeSyntheticEvent<OnTextTracksData>) => void; // android
onSubtitleTracks?: (e: NativeSyntheticEvent<OnSubtitleTracksData>) => void; // iOS
onTextTrackDataChanged?: (
event: NativeSyntheticEvent<OnTextTrackDataChangedData>,
) => void; // iOS
onVideoTracks?: (event: NativeSyntheticEvent<OnVideoTracksData>) => void; // android
}

Expand Down
4 changes: 2 additions & 2 deletions src/types/events.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ export type OnTextTracksData = Readonly<{
textTracks: ReadonlyArray<TextTrack>;
}>;

export type OnSubtitleTracksData = Readonly<{
export type OnTextTrackDataChangedData = Readonly<{
subtitleTracks: string;
}>;

Expand Down Expand Up @@ -185,7 +185,7 @@ export interface ReactVideoEvents {
onTimedMetadata?: (e: OnTimedMetadataData) => void; //Android, iOS
onAudioTracks?: (e: OnAudioTracksData) => void; // Android
onTextTracks?: (e: OnTextTracksData) => void; //Android
onSubtitleTracks?: (e: OnSubtitleTracksData) => void; // iOS
onTextTrackDataChanged?: (e: OnTextTrackDataChangedData) => void; // iOS
onVideoTracks?: (e: OnVideoTracksData) => void; //Android
onAspectRatio?: (e: OnVideoAspectRatioData) => void;
}

0 comments on commit fd76dd9

Please sign in to comment.