Skip to content

Commit ea96e1b

Browse files
committed
fix:限制Linux下MPRIS状态更新的频率,以防止出现抽搐bug。
1 parent 12e65b5 commit ea96e1b

1 file changed

Lines changed: 9 additions & 1 deletion

File tree

src/core/player/MediaSessionManager.ts

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
enableDiscordRpc,
1717
updateDiscordConfig,
1818
} from "./PlayerIpc";
19+
import { throttle } from "lodash-es";
1920

2021
/**
2122
* 媒体会话管理器,负责控制媒体控件相关功能
@@ -236,14 +237,21 @@ class MediaSessionManager {
236237
return;
237238
}
238239
}
240+
this.throttledUpdatePositionState(duration, position);
241+
}
239242

243+
/**
244+
* 媒体会话进度更新限流
245+
* 频繁的更新会导致 Linux 下的 MPRIS 进度条抽搐,因此限制更新频率
246+
*/
247+
private throttledUpdatePositionState = throttle((duration: number, position: number) => {
240248
if ("mediaSession" in navigator) {
241249
navigator.mediaSession.setPositionState({
242250
duration: msToS(duration),
243251
position: msToS(position),
244252
});
245253
}
246-
}
254+
}, 1000);
247255
}
248256

249257
/**

0 commit comments

Comments
 (0)