Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(caption): Add caption control #101

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions packages/media-console/src/VideoPlayer.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ const AnimatedVideoPlayer = (
disableBack = false,
disableVolume = false,
disableFullscreen = false,
disableCaption = false,
disableTimer = false,
disableSeekbar = false,
disablePlayPause = false,
Expand Down Expand Up @@ -106,10 +107,12 @@ const AnimatedVideoPlayer = (
const [currentTime, setCurrentTime] = useState(0);
const [error, setError] = useState(false);
const [duration, setDuration] = useState(0);
const [isCaption, setIsCaption] = useState<boolean>(false);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
const [isCaption, setIsCaption] = useState<boolean>(false);
const [isCaptionEnabled, setIsCaptionEnabled] = useState<boolean>(false);


const videoRef = props.videoRef || _videoRef;

const toggleFullscreen = () => setIsFullscreen((prevState) => !prevState);
const toggleCaption = () => setIsCaption((prevState) => !prevState);
const toggleControls = () =>
setShowControls((prevState) => alwaysShowControls || !prevState);
const toggleTimer = () => setShowTimeRemaining((prevState) => !prevState);
Expand Down Expand Up @@ -404,6 +407,7 @@ const AnimatedVideoPlayer = (
<Video
{...props}
{...events}
selectedTextTrack={isCaption ? props.selectedTextTrack : undefined}
ref={videoRef || _videoRef}
resizeMode={_resizeMode}
volume={_volume}
Expand Down Expand Up @@ -465,8 +469,11 @@ const AnimatedVideoPlayer = (
seekerPosition={seekerPosition}
setSeekerWidth={setSeekerWidth}
isFullscreen={isFullscreen}
isCaption={isCaption}
disableFullscreen={disableFullscreen}
disableCaption={disableCaption}
toggleFullscreen={toggleFullscreen}
toggleCaption={toggleCaption}
showControls={showControls}
/>
</>
Expand Down
Binary file added packages/media-console/src/assets/img/caption.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
24 changes: 24 additions & 0 deletions packages/media-console/src/components/BottomControls.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import {Seekbar} from './Seekbar';
import {calculateTime} from '../utils';
import type {VideoAnimations} from '../types';
import {styles} from './styles';
import {Caption} from './Caption';

interface BottomControlsProps {
showControls: boolean;
Expand All @@ -34,8 +35,11 @@ interface BottomControlsProps {
seekerPosition: number;
setSeekerWidth: Dispatch<SetStateAction<number>>;
isFullscreen: boolean;
isCaption: boolean;
disableFullscreen: boolean;
disableCaption: boolean;
toggleFullscreen: () => void;
toggleCaption: () => void;
}

export const BottomControls = ({
Expand All @@ -57,8 +61,11 @@ export const BottomControls = ({
seekerPosition,
setSeekerWidth,
isFullscreen,
isCaption,
disableFullscreen,
disableCaption,
toggleFullscreen,
toggleCaption,
}: BottomControlsProps) => {
const timerControl = disableTimer ? (
<NullControl />
Expand Down Expand Up @@ -100,6 +107,16 @@ export const BottomControls = ({
/>
);

const captionControl = disableCaption ? (
<NullControl />
) : (
<Caption
isCaption={isCaption}
toggleCaption={toggleCaption}
showControls={showControls}
/>
);

return (
<AnimatedView
style={[
Expand All @@ -114,6 +131,9 @@ export const BottomControls = ({
<SafeAreaView style={[styles.row, _styles.bottomControlGroup]}>
{timerControl}
<Title title={title} />
<SafeAreaView style={_styles.captionContainer}>
{captionControl}
</SafeAreaView>
{fullscreenControl}
</SafeAreaView>
<SafeAreaView style={styles.seekBarContainer}>
Expand All @@ -138,4 +158,8 @@ const _styles = StyleSheet.create({
marginRight: 12,
marginBottom: 0,
},
captionContainer: {
marginLeft: 'auto',
marginBottom: 0,
},
});
35 changes: 35 additions & 0 deletions packages/media-console/src/components/Caption.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import React from 'react';
import {Image, StyleSheet} from 'react-native';
import {Control} from './Control';

interface CaptionProps {
isCaption: boolean;
toggleCaption: () => void;
showControls: boolean;
}

export const Caption = ({
isCaption,
toggleCaption,

showControls,
}: CaptionProps) => {
return (
<Control
callback={toggleCaption}
style={[styles.caption, isCaption && styles.captionActive]}
disabled={!showControls}>
<Image source={require('../assets/img/caption.png')} />
</Control>
);
};

const styles = StyleSheet.create({
caption: {
flexDirection: 'row',
padding: 4,
},
captionActive: {
opacity: 1,
},
});
7 changes: 7 additions & 0 deletions packages/media-console/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,13 @@ export interface VideoPlayerProps extends ReactVideoProps {
*/
disableFullscreen?: boolean;

/**
* Show the caption button
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
* Show the caption button
* Hide the caption button

*
* @default false
*/
disableCaption?: boolean;

/**
* Hide the timer
*
Expand Down