chore: 线上能够播放音乐的版本
This commit is contained in:
@@ -102,31 +102,31 @@ class MusicPlayer {
|
||||
console.log("音乐已暂停");
|
||||
}
|
||||
}
|
||||
/**
|
||||
* 新增:设置静音/取消静音(适配管理员/首页场景)
|
||||
* @param {boolean} muted 是否静音
|
||||
*/
|
||||
setMuted(muted) {
|
||||
if (this.audio) {
|
||||
this.audio.muted = muted;
|
||||
console.log(muted ? "音乐已静音" : "音乐已取消静音");
|
||||
/**
|
||||
* 新增:设置静音/取消静音(适配管理员/首页场景)
|
||||
* @param {boolean} muted 是否静音
|
||||
*/
|
||||
setMuted(muted) {
|
||||
if (this.audio) {
|
||||
this.audio.muted = muted;
|
||||
console.log(muted ? "音乐已静音" : "音乐已取消静音");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置音量
|
||||
* @param {number} volume 音量值 (0.0 到 1.0)
|
||||
*/
|
||||
setVolume(volume) {
|
||||
if (this.audio) {
|
||||
// 确保音量是数字类型
|
||||
const numericVolume = typeof volume === 'string' ? parseFloat(volume) : volume;
|
||||
// 限制音量范围在0.0到1.0之间
|
||||
this.volume = Math.max(0, Math.min(1, numericVolume));
|
||||
this.audio.volume = this.volume;
|
||||
console.log(`音乐音量已设置为: ${Math.round(this.volume * 100)}%`);
|
||||
/**
|
||||
* 设置音量
|
||||
* @param {number} volume 音量值 (0.0 到 1.0)
|
||||
*/
|
||||
setVolume(volume) {
|
||||
if (this.audio) {
|
||||
// 确保音量是数字类型
|
||||
const numericVolume = typeof volume === 'string' ? parseFloat(volume) : volume;
|
||||
// 限制音量范围在0.0到1.0之间
|
||||
this.volume = Math.max(0, Math.min(1, numericVolume));
|
||||
this.audio.volume = this.volume;
|
||||
console.log(`音乐音量已设置为: ${Math.round(this.volume * 100)}%`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 新增:stop 方法(组件 onUnmounted 调用,暂停+重置进度)
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
<template>
|
||||
<div @click.once="handleFirstInteraction">
|
||||
<div @click="handleAnyInteraction" @scroll="handleAnyInteraction" @touchstart="handleAnyInteraction">
|
||||
<!-- 第一部分:百日大战主题 - 使用banner0.png图片 -->
|
||||
<section class="theme-section card-game">
|
||||
<div class="theme-container">
|
||||
@@ -421,6 +421,15 @@ const handleFirstInteraction = () => {
|
||||
}
|
||||
};
|
||||
|
||||
// 添加任意交互处理函数(点击、滚动等都会触发)
|
||||
const handleAnyInteraction = () => {
|
||||
// 只有在音乐启用且当前未播放时才尝试播放
|
||||
if (localMusicConfig.value.enabled && !musicPlayer.isPlaying) {
|
||||
console.log("检测到用户交互,尝试播放音乐...");
|
||||
musicPlayer.play();
|
||||
}
|
||||
};
|
||||
|
||||
// 加载任务设置和初始化所有数据
|
||||
onBeforeMount(async () => {
|
||||
try {
|
||||
|
||||
Reference in New Issue
Block a user