Skip to content

Commit 1ea562a

Browse files
committed
fix(player): toggle captions on plyr layout should show cue
1 parent 87340eb commit 1ea562a

2 files changed

Lines changed: 15 additions & 8 deletions

File tree

packages/react/src/components/layouts/plyr/layout.tsx

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -752,9 +752,13 @@ function PlyrCaptions() {
752752

753753
React.useEffect(() => {
754754
if (!$track) return;
755-
return listenEvent($track, 'cue-change', () => {
756-
setActiveCue($track?.activeCues[0]);
757-
});
755+
756+
function onCueChange() {
757+
setActiveCue($track ? $track.activeCues[0] : null);
758+
}
759+
760+
onCueChange();
761+
return listenEvent($track, 'cue-change', onCueChange);
758762
}, [$track]);
759763

760764
return (

packages/vidstack/src/elements/define/layouts/plyr/shared-layout.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -507,11 +507,14 @@ function Captions() {
507507

508508
effect(() => {
509509
const track = media.$state.textTrack();
510-
return track
511-
? listenEvent(track, 'cue-change', () => {
512-
activeCue.set(track?.activeCues[0]);
513-
})
514-
: null;
510+
if (!track) return;
511+
512+
function onCueChange() {
513+
activeCue.set(track?.activeCues[0]);
514+
}
515+
516+
onCueChange();
517+
return listenEvent(track, 'cue-change', onCueChange);
515518
});
516519

517520
return html`

0 commit comments

Comments
 (0)