Skip to content

Commit 41d6dc3

Browse files
authored
Merge pull request #706 from MoYingJi/pr/b
feat(playBackground): 支持暂停时暂停背景动画
2 parents 4419180 + e2e54ea commit 41d6dc3

5 files changed

Lines changed: 25 additions & 5 deletions

File tree

src/components/Player/PlayerBackground.vue

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,25 @@
2020
v-else-if="settingStore.playerBackgroundType === 'animation'"
2121
:album="musicStore.songCover"
2222
:fps="settingStore.playerBackgroundFps ?? 60"
23-
:flowSpeed="settingStore.playerBackgroundFlowSpeed ?? 4"
23+
:flowSpeed="flowSpeed"
2424
:hasLyric="musicStore.isHasLrc"
2525
/>
2626
</Transition>
2727
</div>
2828
</template>
2929

3030
<script setup lang="ts">
31-
import { useMusicStore, useSettingStore } from "@/stores";
31+
import { useMusicStore, useSettingStore, useStatusStore } from "@/stores";
3232
import BackgroundRender from "../Special/BackgroundRender.vue";
3333
3434
const musicStore = useMusicStore();
3535
const settingStore = useSettingStore();
36+
const statusStore = useStatusStore();
37+
38+
const flowSpeed = computed(() => {
39+
if (!statusStore.playStatus && settingStore.playerBackgroundPause) return 0;
40+
else return settingStore.playerBackgroundFlowSpeed ?? 4;
41+
})
3642
</script>
3743

3844
<style lang="scss" scoped>

src/components/Player/PlayerControl.vue

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,6 @@ const { timeDisplay, toggleTimeFormat } = useTimeFormat();
137137
width: 100%;
138138
height: 80px;
139139
overflow: hidden;
140-
cursor: pointer;
141140
.control-content {
142141
width: 100%;
143142
height: 100%;
@@ -250,14 +249,14 @@ const { timeDisplay, toggleTimeFormat } = useTimeFormat();
250249
width: 100%;
251250
max-width: 480px;
252251
font-size: 12px;
253-
cursor: pointer;
254252
.n-slider {
255253
margin: 6px 8px;
256254
--n-handle-size: 12px;
257255
--n-rail-height: 4px;
258256
}
259257
span {
260258
opacity: 0.6;
259+
cursor: pointer;
261260
}
262261
}
263262
}

src/components/Setting/PlaySetting.vue

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,13 @@
235235
placeholder="请输入背景动画流动速度"
236236
/>
237237
</n-card>
238+
<n-card class="set-item">
239+
<div class="label">
240+
<n-text class="name">背景动画暂停时暂停</n-text>
241+
<n-text class="tip" :depth="3">在暂停时是否也暂停背景动画</n-text>
242+
</div>
243+
<n-switch v-model:value="settingStore.playerBackgroundPause" class="set" :round="false" />
244+
</n-card>
238245
</n-collapse-transition>
239246
<n-card class="set-item">
240247
<div class="label">

src/components/Special/BackgroundRender.vue

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,11 +93,16 @@ onMounted(() => {
9393
}
9494
});
9595
96-
onUnmounted(() => {
96+
const { start: delayedDispose } = useTimeoutFn(() => {
9797
if (bgRenderRef.value) {
9898
bgRenderRef.value.dispose();
9999
bgRenderRef.value = undefined;
100100
}
101+
}, 500, { immediate: false });
102+
103+
onBeforeUnmount(() => {
104+
bgRenderRef.value?.pause();
105+
delayedDispose();
101106
});
102107
103108
watch(

src/stores/setting.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,8 @@ export interface SettingState {
139139
playerBackgroundFps: number;
140140
/** 背景动画流动速度 */
141141
playerBackgroundFlowSpeed: number;
142+
/** 背景动画是否在歌曲暂停时暂停 */
143+
playerBackgroundPause: boolean
142144
/** 播放器元素自动隐藏 */
143145
autoHidePlayerMeta: boolean;
144146
/** 记忆最后进度 */
@@ -339,6 +341,7 @@ export const useSettingStore = defineStore("setting", {
339341
playerBackgroundType: "blur",
340342
playerBackgroundFps: 30,
341343
playerBackgroundFlowSpeed: 4,
344+
playerBackgroundPause: false,
342345
autoHidePlayerMeta: true,
343346
memoryLastSeek: true,
344347
progressTooltipShow: true,

0 commit comments

Comments
 (0)