Skip to content

Commit

Permalink
feedback addressed
Browse files Browse the repository at this point in the history
  • Loading branch information
JimLiu committed Jun 20, 2019
1 parent 2842ce8 commit 183be89
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 15 deletions.
2 changes: 1 addition & 1 deletion docs/lib/Components/CaptionedVideoPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const PlayerWithCaptionsSource = require('!!raw-loader!../examples/PlayerWithCap
export default function CaptionedVideoPage() {
return (
<div>
<Helmet title="PosterImage" />
<Helmet title="ClosedCaptionButton" />
<h3>ClosedCaptionButton</h3>
<p>
There is an example on how to add a ClosedCaption button component into{' '}
Expand Down
26 changes: 17 additions & 9 deletions src/components/control-bar/ClosedCaptionButton.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ const propTypes = {
player: PropTypes.object,
actions: PropTypes.object,
className: PropTypes.string,
offMenuText: PropTypes.string,
showOffMenu: PropTypes.bool,
kinds: PropTypes.array
};

const defaultProps = {
offMenuText: 'Off',
showOffMenu: true,
kinds: ['captions', 'subtitles'] // `kind`s of TextTrack to look for to associate it with this menu.
};

Expand All @@ -30,7 +34,9 @@ class ClosedCaptionButton extends Component {
}

getTextTrackItems() {
const { kinds, player } = this.props;
const {
kinds, player, offMenuText, showOffMenu
} = this.props;
const { textTracks, activeTextTrack } = player;
const textTrackItems = {
items: [],
Expand All @@ -42,10 +48,12 @@ class ClosedCaptionButton extends Component {
return textTrackItems;
}

textTrackItems.items.push({
label: 'Off',
value: null
});
if (showOffMenu) {
textTrackItems.items.push({
label: offMenuText || 'Off',
value: null
});
}

tracks.forEach((textTrack) => {
// ignore invalid text track kind
Expand Down Expand Up @@ -99,14 +107,14 @@ class ClosedCaptionButton extends Component {
}

handleSelectItem(index) {
const { player, actions } = this.props;
const { player, actions, showOffMenu } = this.props;
const { textTracks } = player;

// For the 'subtitles-off' button, the first condition will never match
// so all will subtitles be turned off
// so all subtitles will be turned off
Array.from(textTracks).forEach((textTrack, i) => {
if (index === i + 1) {
// the 0 index is `Off`
// if it shows the `Off` menu, the first item is `Off`
if (index === (showOffMenu ? i + 1 : i)) {
textTrack.mode = 'showing';
actions.activateTextTrack(textTrack);
} else {
Expand Down
17 changes: 12 additions & 5 deletions styles/scss/components/closed-caption.scss
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
.video-react .video-react-closed-caption {
cursor: pointer;
@include flex(none);
@extend .video-react-icon;
@extend .video-react-icon-closed-caption;
.video-react {
.video-react-closed-caption {
cursor: pointer;
@include flex(none);
@extend .video-react-icon;
@extend .video-react-icon-closed-caption;
}

video::-webkit-media-text-track-container {
-webkit-transform: translateY(-30px) !important;
transform: translateY(-30px) !important;
}
}

0 comments on commit 183be89

Please sign in to comment.