mirror of
https://github.com/stashapp/stash.git
synced 2025-12-18 21:04:37 +03:00
Add persist volume plugin (#2448)
This commit is contained in:
@@ -6,6 +6,7 @@ import "videojs-seek-buttons";
|
|||||||
import "videojs-landscape-fullscreen";
|
import "videojs-landscape-fullscreen";
|
||||||
import "./live";
|
import "./live";
|
||||||
import "./PlaylistButtons";
|
import "./PlaylistButtons";
|
||||||
|
import "./persist-volume";
|
||||||
import "./markers";
|
import "./markers";
|
||||||
import cx from "classnames";
|
import cx from "classnames";
|
||||||
|
|
||||||
@@ -164,6 +165,7 @@ export const ScenePlayer: React.FC<IScenePlayerProps> = ({
|
|||||||
|
|
||||||
(player as any).markers();
|
(player as any).markers();
|
||||||
(player as any).offset();
|
(player as any).offset();
|
||||||
|
(player as any).persistVolume();
|
||||||
|
|
||||||
player.focus();
|
player.focus();
|
||||||
playerRef.current = player;
|
playerRef.current = player;
|
||||||
|
|||||||
30
ui/v2.5/src/components/ScenePlayer/persist-volume.ts
Normal file
30
ui/v2.5/src/components/ScenePlayer/persist-volume.ts
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
import videojs, { VideoJsPlayer } from "video.js";
|
||||||
|
import localForage from "localforage";
|
||||||
|
|
||||||
|
const persistVolume = function (this: VideoJsPlayer) {
|
||||||
|
const player = this;
|
||||||
|
const levelKey = "volume-level";
|
||||||
|
const mutedKey = "volume-muted";
|
||||||
|
|
||||||
|
player.on("volumechange", function () {
|
||||||
|
localForage.setItem(levelKey, player.volume());
|
||||||
|
localForage.setItem(mutedKey, player.muted());
|
||||||
|
});
|
||||||
|
|
||||||
|
localForage.getItem(levelKey).then((value) => {
|
||||||
|
if (value !== null) {
|
||||||
|
player.volume(value as number);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
localForage.getItem(mutedKey).then((value) => {
|
||||||
|
if (value !== null) {
|
||||||
|
player.muted(value as boolean);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
// Register the plugin with video.js.
|
||||||
|
videojs.registerPlugin("persistVolume", persistVolume);
|
||||||
|
|
||||||
|
export default persistVolume;
|
||||||
Reference in New Issue
Block a user