Skip to content

Commit

Permalink
Fix broken captions button reference in handleCaptionChange()
Browse files Browse the repository at this point in the history
  • Loading branch information
Dananji committed Jul 31, 2024
1 parent 8ff42ea commit f127f8e
Showing 1 changed file with 9 additions and 4 deletions.
13 changes: 9 additions & 4 deletions src/components/MediaPlayer/VideoJS/VideoJSPlayer.js
Original file line number Diff line number Diff line change
Expand Up @@ -741,19 +741,24 @@ function VideoJSPlayer({
*/
const handleCaptionChange = (subsOn) => {
let player = playerRef.current;
/**
* When subsCapsButton is not setup on Video.js initialization step, and is
* later added in updatePlayer() function player.controlBar.getChild() method
* needs to be used to access it.
*/
const subsCapsBtn = player.controlBar.getChild('subsCapsButton');
/*
For audio instances Video.js is setup to not to build the CC button
in Ramp's player control bar.
*/
if (!player.controlBar.subsCapsButton
|| !player.controlBar.subsCapsButton?.children_) {
if (subsCapsBtn == undefined || !subsCapsBtn || !subsCapsBtn?.children_) {
return;
}
if (subsOn) {
player.controlBar.subsCapsButton.children_[0].addClass('captions-on');
subsCapsBtn.children_[0].addClass('captions-on');
captionsOnRef.current = true;
} else {
player.controlBar.subsCapsButton.children_[0].removeClass('captions-on');
subsCapsBtn.children_[0].removeClass('captions-on');
captionsOnRef.current = false;
}
};
Expand Down

0 comments on commit f127f8e

Please sign in to comment.