mirror of
https://github.com/algerkong/AlgerMusicPlayer.git
synced 2026-05-19 03:57:28 +08:00
fix(player): 静音保留原音量,解除后可恢复
- playerCore 新增持久化 isMuted 状态及 setMuted/toggleMute,静音时音频输出置 0 但 volume 保持不变 - 音量 > 0 时自动解除静音 - useVolumeControl 移除原 0↔30 切换;滑块/百分比展示真实音量,图标反映静音态 - 三个播放栏的音量滑块在静音时 disabled;PlayBar 百分比文字同步置灰(仅文字颜色)
This commit is contained in:
@@ -41,6 +41,7 @@ export const usePlayerStore = defineStore('player', () => {
|
||||
musicFull,
|
||||
playbackRate,
|
||||
volume,
|
||||
isMuted,
|
||||
userPlayIntent,
|
||||
isFmPlaying
|
||||
} = storeToRefs(playerCore);
|
||||
@@ -97,6 +98,7 @@ export const usePlayerStore = defineStore('player', () => {
|
||||
musicFull,
|
||||
playbackRate,
|
||||
volume,
|
||||
isMuted,
|
||||
userPlayIntent,
|
||||
isFmPlaying,
|
||||
|
||||
@@ -113,6 +115,8 @@ export const usePlayerStore = defineStore('player', () => {
|
||||
getVolume: playerCore.getVolume,
|
||||
increaseVolume: playerCore.increaseVolume,
|
||||
decreaseVolume: playerCore.decreaseVolume,
|
||||
setMuted: playerCore.setMuted,
|
||||
toggleMute: playerCore.toggleMute,
|
||||
handlePause: playerCore.handlePause,
|
||||
|
||||
// ========== 播放列表管理 (Playlist) ==========
|
||||
|
||||
@@ -20,6 +20,7 @@ export const usePlayerCoreStore = defineStore(
|
||||
const musicFull = ref(false);
|
||||
const playbackRate = ref(1.0);
|
||||
const volume = ref(1);
|
||||
const isMuted = ref(false);
|
||||
const userPlayIntent = ref(false); // 用户是否想要播放
|
||||
const isFmPlaying = ref(false); // 是否正在播放私人FM
|
||||
|
||||
@@ -65,7 +66,27 @@ export const usePlayerCoreStore = defineStore(
|
||||
const setVolume = (newVolume: number) => {
|
||||
const normalizedVolume = Math.max(0, Math.min(1, newVolume));
|
||||
volume.value = normalizedVolume;
|
||||
audioService.setVolume(normalizedVolume);
|
||||
// 用户调高音量时自动解除静音
|
||||
if (isMuted.value && normalizedVolume > 0) {
|
||||
isMuted.value = false;
|
||||
}
|
||||
audioService.setVolume(isMuted.value ? 0 : normalizedVolume);
|
||||
};
|
||||
|
||||
/**
|
||||
* 设置静音状态(不改变 volume,仅控制音频输出)
|
||||
*/
|
||||
const setMuted = (value: boolean) => {
|
||||
if (isMuted.value === value) return;
|
||||
isMuted.value = value;
|
||||
audioService.setVolume(isMuted.value ? 0 : volume.value);
|
||||
};
|
||||
|
||||
/**
|
||||
* 切换静音
|
||||
*/
|
||||
const toggleMute = () => {
|
||||
setMuted(!isMuted.value);
|
||||
};
|
||||
|
||||
/**
|
||||
@@ -169,6 +190,7 @@ export const usePlayerCoreStore = defineStore(
|
||||
musicFull,
|
||||
playbackRate,
|
||||
volume,
|
||||
isMuted,
|
||||
userPlayIntent,
|
||||
isFmPlaying,
|
||||
audioOutputDeviceId,
|
||||
@@ -187,6 +209,8 @@ export const usePlayerCoreStore = defineStore(
|
||||
getVolume,
|
||||
increaseVolume,
|
||||
decreaseVolume,
|
||||
setMuted,
|
||||
toggleMute,
|
||||
handlePause,
|
||||
refreshAudioDevices,
|
||||
setAudioOutputDevice,
|
||||
@@ -197,7 +221,15 @@ export const usePlayerCoreStore = defineStore(
|
||||
persist: {
|
||||
key: 'player-core-store',
|
||||
storage: localStorage,
|
||||
pick: ['playMusic', 'playMusicUrl', 'playbackRate', 'volume', 'isPlay', 'audioOutputDeviceId']
|
||||
pick: [
|
||||
'playMusic',
|
||||
'playMusicUrl',
|
||||
'playbackRate',
|
||||
'volume',
|
||||
'isMuted',
|
||||
'isPlay',
|
||||
'audioOutputDeviceId'
|
||||
]
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user