Skip to content
Open
Show file tree
Hide file tree
Changes from all 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
45 changes: 45 additions & 0 deletions src/js/plugins/captions-autoscroll.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// src/js/plugins/captions-autoscroll.js

/**
* Captions Auto-scroll Plugin
*
* This plugin keeps the active transcript/caption line
* in view while the media is playing.
*
* NOTE:
* - Opt-in only
* - Does NOT modify existing captions rendering
*/

export default function captionsAutoscroll(player, options = {}) {
if (!player) {
return;
}

const config = {
enabled: false,
smooth: true,
offset: 0,
transcriptContainer: null,
...options,
};

function enable() {
config.enabled = true;
}

function disable() {
config.enabled = false;
}

function destroy() {
disable();
}

// Public API (attached to player)
player.autoscrollCaptions = {
enable,
disable,
destroy,
};
}
6 changes: 6 additions & 0 deletions src/js/plyr.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import html5 from './html5';
import Listeners from './listeners';
import media from './media';
import Ads from './plugins/ads';
import captionsAutoscroll from './plugins/captions-autoscroll';
import PreviewThumbnails from './plugins/preview-thumbnails';
import source from './source';
import Storage from './storage';
Expand Down Expand Up @@ -101,6 +102,11 @@ class Plyr {
currentTrack: -1,
meta: new WeakMap(),
};
// Captions autoscroll plugin (keeps active cue in view)

if (this.config.captions?.enabled !== false) {
this.captionsAutoscroll = captionsAutoscroll(this);
}

// Fullscreen
this.fullscreen = {
Expand Down