mirror of
https://github.com/trafficlunar/jellyfin-spicetify.git
synced 2026-06-13 19:07:06 +00:00
fix: sync oldTime when toggling audio, and debug messages
This commit is contained in:
parent
f8664bfea8
commit
2cdc4a92d4
2 changed files with 21 additions and 4 deletions
|
|
@ -42,12 +42,18 @@ async function main() {
|
|||
if (self.active) {
|
||||
player.stop();
|
||||
} else {
|
||||
// Set volume
|
||||
const oldVolume = player.currentVolume;
|
||||
Spicetify.Player.setVolume(0); // Set Spotify audio volume
|
||||
player.hijackActive.set(true);
|
||||
Spicetify.Player.setVolume(oldVolume); // Hijack is active, set Jellyfin audio volume
|
||||
|
||||
player.audio.currentTime = Spicetify.Player.getProgress() / 1000; // Sync position
|
||||
// Sync positions
|
||||
const time = Spicetify.Player.getProgress();
|
||||
player.audio.currentTime = time / 1000;
|
||||
player.setOldTime(time);
|
||||
|
||||
// Play
|
||||
if (Spicetify.Player.isPlaying()) player.audio.play();
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -16,6 +16,11 @@ let currentItemId: string | null = null;
|
|||
let oldTime = 0;
|
||||
let lastProgressReport = 0;
|
||||
|
||||
export function setOldTime(value: number) {
|
||||
// no signal because we don't need to subscribe to it
|
||||
oldTime = value;
|
||||
}
|
||||
|
||||
const BITRATE_MAP: Record<string, string> = {
|
||||
high: "320000",
|
||||
medium: "256000",
|
||||
|
|
@ -55,7 +60,7 @@ export async function playTrack(id: string) {
|
|||
});
|
||||
|
||||
audio.src = `${jellyfin.api.basePath}/Audio/${id}/universal?${params}`;
|
||||
console.log("[Jellyfin]: Attempting to play:", audio.src);
|
||||
console.debug("[Jellyfin]: Attempting to play:", audio.src);
|
||||
await audio.play();
|
||||
|
||||
if (settings.reportPlayback) {
|
||||
|
|
@ -112,9 +117,13 @@ export function registerEvents() {
|
|||
|
||||
const results = new Fuse(list, {
|
||||
keys: ["name", "artists"],
|
||||
threshold: 0.5,
|
||||
threshold: 0.7,
|
||||
}).search(`${trackName} ${artists}`);
|
||||
|
||||
console.debug(`[Jellyfin]: Query is "${trackName} ${artists}"`);
|
||||
console.debug("[Jellyfin]: Search list:", list);
|
||||
console.debug("[Jellyfin]: Fuse search found:", results);
|
||||
|
||||
const track = results[0]?.item;
|
||||
if (!track) {
|
||||
stop();
|
||||
|
|
@ -173,7 +182,7 @@ export function registerEvents() {
|
|||
return;
|
||||
}
|
||||
|
||||
console.log(event.data, oldTime);
|
||||
console.debug(`[Jellyfin]: Seek detected - onprogress reports ${event.data}, old time was ${oldTime}`);
|
||||
|
||||
audio.currentTime = event.data / 1000;
|
||||
oldTime = event.data;
|
||||
|
|
@ -189,6 +198,8 @@ export function registerEvents() {
|
|||
currentVolume = args[0];
|
||||
|
||||
if (hijackActive.get()) {
|
||||
console.debug("[Jellyfin]: Volume is", currentVolume);
|
||||
|
||||
audio.volume = Math.pow(currentVolume, 3) * 0.425;
|
||||
if (volumeSlider) volumeSlider.style.setProperty("--progress-bar-transform", `${currentVolume * 100}%`);
|
||||
if (volumeSliderInput) volumeSliderInput.value = currentVolume.toString();
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue