Save player volume on change
This commit is contained in:
@@ -5,7 +5,7 @@
|
||||
import { SponsorBlock, type Category } from 'sponsorblock-api';
|
||||
import { onDestroy, onMount } from 'svelte';
|
||||
import { get } from 'svelte/store';
|
||||
import type { MediaTimeUpdateEvent, PlayerSrc } from 'vidstack';
|
||||
import type { MediaTimeUpdateEvent, MediaVolumeChangeEvent, PlayerSrc } from 'vidstack';
|
||||
import type { MediaPlayerElement } from 'vidstack/elements';
|
||||
import {
|
||||
playerAlwaysLoop,
|
||||
@@ -38,6 +38,13 @@
|
||||
const proxyVideos = get(playerProxyVideos);
|
||||
|
||||
onMount(async () => {
|
||||
try {
|
||||
const defaultVolume = localStorage.getItem('volume');
|
||||
if (defaultVolume) {
|
||||
player.volume = Number(defaultVolume);
|
||||
}
|
||||
} catch {}
|
||||
|
||||
if (playlistVideos) {
|
||||
player.addEventListener('end', () => {
|
||||
if (!playlistVideos) return;
|
||||
@@ -97,6 +104,12 @@
|
||||
savePlayerPos();
|
||||
});
|
||||
|
||||
player.addEventListener('volume-change', (event: MediaVolumeChangeEvent) => {
|
||||
try {
|
||||
localStorage.setItem('volume', event.detail.volume.toString());
|
||||
} catch {}
|
||||
});
|
||||
|
||||
if (get(sponsorBlockCategories)) {
|
||||
const currentCategories = get(sponsorBlockCategories);
|
||||
|
||||
@@ -152,10 +165,12 @@
|
||||
}
|
||||
|
||||
if (get(playerSavePlaybackPosition)) {
|
||||
const playerPos = localStorage.getItem(`v_${data.video.videoId}`);
|
||||
if (playerPos) {
|
||||
player.currentTime = Number(playerPos);
|
||||
}
|
||||
try {
|
||||
const playerPos = localStorage.getItem(`v_${data.video.videoId}`);
|
||||
if (playerPos) {
|
||||
player.currentTime = Number(playerPos);
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
} else {
|
||||
src = [
|
||||
@@ -197,13 +212,15 @@
|
||||
});
|
||||
|
||||
function savePlayerPos() {
|
||||
if (get(playerSavePlaybackPosition) && player.currentTime) {
|
||||
if (player.currentTime < player.duration - 10 && player.currentTime > 10) {
|
||||
localStorage.setItem(`v_${data.video.videoId}`, player.currentTime.toString());
|
||||
} else {
|
||||
localStorage.removeItem(`v_${data.video.videoId}`);
|
||||
try {
|
||||
if (get(playerSavePlaybackPosition) && player.currentTime) {
|
||||
if (player.currentTime < player.duration - 10 && player.currentTime > 10) {
|
||||
localStorage.setItem(`v_${data.video.videoId}`, player.currentTime.toString());
|
||||
} else {
|
||||
localStorage.removeItem(`v_${data.video.videoId}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
} catch {}
|
||||
}
|
||||
|
||||
onDestroy(() => {
|
||||
@@ -224,6 +241,7 @@
|
||||
streamType={data.video.hlsUrl ? 'live' : 'on-demand'}
|
||||
viewType={audioMode ? 'audio' : 'video'}
|
||||
playsInline={true}
|
||||
keep-alive
|
||||
{src}
|
||||
>
|
||||
<media-provider>
|
||||
|
||||
@@ -18,7 +18,11 @@
|
||||
|
||||
let progress: string | null;
|
||||
if (get(playerSavePlaybackPosition)) {
|
||||
progress = localStorage.getItem(`v_${video.videoId}`);
|
||||
try {
|
||||
progress = localStorage.getItem(`v_${video.videoId}`);
|
||||
} catch {
|
||||
progress = null;
|
||||
}
|
||||
} else {
|
||||
progress = null;
|
||||
}
|
||||
|
||||
@@ -40,7 +40,6 @@ export interface PhasedDescription {
|
||||
|
||||
export function phaseDescription(content: string): PhasedDescription {
|
||||
const timestamps: { title: string; time: number; timePretty: string; }[] = [];
|
||||
console.log(content);
|
||||
const lines = content.split('\n');
|
||||
|
||||
const urlRegex = /<a href="([^"]+)"/;
|
||||
|
||||
@@ -52,11 +52,13 @@
|
||||
on:click={async () => {
|
||||
await deleteHistory();
|
||||
history = [];
|
||||
Object.keys(localStorage).forEach((key) => {
|
||||
if (key.startsWith('v_')) {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
});
|
||||
try {
|
||||
Object.keys(localStorage).forEach((key) => {
|
||||
if (key.startsWith('v_')) {
|
||||
localStorage.removeItem(key);
|
||||
}
|
||||
});
|
||||
} catch {}
|
||||
}}
|
||||
>
|
||||
<i>delete_sweep</i>
|
||||
|
||||
Reference in New Issue
Block a user