mirror of
https://github.com/stashapp/stash.git
synced 2025-12-24 09:12:39 +01:00
* Add types to player plugins * Use videojs-vtt.js to parse sprite VTT files * Overhaul scene player * Replace vtt-thumbnails-freetube * Remove chapters_vtt * Force remove shadow from player progress bar * Cleanup player css * Rewrite live.ts as middleware * Don't force play when changing source
59 lines
1.4 KiB
TypeScript
59 lines
1.4 KiB
TypeScript
import videojs, { VideoJsPlayer } from "video.js";
|
|
import localForage from "localforage";
|
|
|
|
const levelKey = "volume-level";
|
|
const mutedKey = "volume-muted";
|
|
|
|
interface IPersistVolumeOptions {
|
|
enabled?: boolean;
|
|
}
|
|
|
|
class PersistVolumePlugin extends videojs.getPlugin("plugin") {
|
|
enabled: boolean;
|
|
|
|
constructor(player: VideoJsPlayer, options?: IPersistVolumeOptions) {
|
|
super(player, options);
|
|
|
|
this.enabled = options?.enabled ?? true;
|
|
|
|
player.on("volumechange", () => {
|
|
if (this.enabled) {
|
|
localForage.setItem(levelKey, player.volume());
|
|
localForage.setItem(mutedKey, player.muted());
|
|
}
|
|
});
|
|
|
|
player.ready(() => {
|
|
this.ready();
|
|
});
|
|
}
|
|
|
|
private ready() {
|
|
localForage.getItem<number>(levelKey).then((value) => {
|
|
if (value !== null) {
|
|
this.player.volume(value);
|
|
}
|
|
});
|
|
|
|
localForage.getItem<boolean>(mutedKey).then((value) => {
|
|
if (value !== null) {
|
|
this.player.muted(value);
|
|
}
|
|
});
|
|
}
|
|
}
|
|
|
|
// Register the plugin with video.js.
|
|
videojs.registerPlugin("persistVolume", PersistVolumePlugin);
|
|
|
|
/* eslint-disable @typescript-eslint/naming-convention */
|
|
declare module "video.js" {
|
|
interface VideoJsPlayer {
|
|
persistVolume: () => PersistVolumePlugin;
|
|
}
|
|
interface VideoJsPlayerPluginOptions {
|
|
persistVolume?: IPersistVolumeOptions;
|
|
}
|
|
}
|
|
|
|
export default PersistVolumePlugin;
|