Skip to content

Commit

Permalink
🐞 fix: 修复音量调节
Browse files Browse the repository at this point in the history
  • Loading branch information
imsyy committed Dec 11, 2024
1 parent 191ab29 commit 9accf5d
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 6 deletions.
2 changes: 2 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,7 @@
"localforage": "^1.10.0",
"lodash-es": "^4.17.21",
"marked": "^14.1.4",
"md5": "^2.3.0",
"music-metadata": "7.14.0",
"pinia": "^2.3.0",
"pinia-plugin-persistedstate": "^4.1.3",
Expand All @@ -83,6 +84,7 @@
"@types/file-saver": "^2.0.7",
"@types/howler": "^2.2.12",
"@types/js-cookie": "^3.0.6",
"@types/md5": "^2.3.5",
"@types/node": "^22.10.1",
"@typescript-eslint/eslint-plugin": "^8.18.0",
"@typescript-eslint/parser": "^8.18.0",
Expand Down
11 changes: 11 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 12 additions & 6 deletions src/utils/player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -760,20 +760,26 @@ class Player {
* 设置播放音量
* @param actions 音量
*/
setVolume(actions: number | WheelEvent) {
setVolume(actions: number | "up" | "down" | WheelEvent) {
const statusStore = useStatusStore();
const increment = 0.05;
// 直接设置
if (typeof actions === "number") {
actions = Math.max(0, Math.min(actions, 1));
} else {
const increment = 0.05;
const deltaY = actions.deltaY;
const volume = deltaY > 0 ? "down" : "up";
}
// 分类调节
else if (actions === "up" || actions === "down") {
statusStore.playVolume = Math.max(
0,
Math.min(statusStore.playVolume + (volume === "up" ? increment : -increment), 1),
Math.min(statusStore.playVolume + (actions === "up" ? increment : -increment), 1),
);
}
// 鼠标滚轮
else {
const deltaY = actions.deltaY;
const volumeChange = deltaY > 0 ? -increment : increment;
statusStore.playVolume = Math.max(0, Math.min(statusStore.playVolume + volumeChange, 1));
}
// 调整音量
this.player.volume(statusStore.playVolume);
}
Expand Down

0 comments on commit 9accf5d

Please sign in to comment.