AudioManager.ts 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758
  1. import { _decorator, Component, AudioClip, AudioSource, resources, Node } from 'cc';
  2. import { BundleLoader } from '../Core/BundleLoader';
  3. const { ccclass, property } = _decorator;
  4. /**
  5. * 音频管理器
  6. * 统一管理游戏中的音乐和音效播放
  7. */
  8. @ccclass('AudioManager')
  9. export class AudioManager extends Component {
  10. // 音频源组件
  11. @property({ type: AudioSource, tooltip: '背景音乐播放器' })
  12. public musicAudioSource: AudioSource = null;
  13. @property({ type: AudioSource, tooltip: 'UI音效播放器' })
  14. public uiSoundAudioSource: AudioSource = null;
  15. @property({ type: AudioSource, tooltip: '敌人音效播放器' })
  16. public enemySoundAudioSource: AudioSource = null;
  17. @property({ type: AudioSource, tooltip: '环境音效播放器' })
  18. public environmentSoundAudioSource: AudioSource = null;
  19. @property({ type: AudioSource, tooltip: '武器音效播放器' })
  20. public weaponSoundAudioSource: AudioSource = null;
  21. // 音量设置
  22. private musicVolume: number = 0.8;
  23. private uiSoundVolume: number = 0.8;
  24. private enemySoundVolume: number = 0.8;
  25. private environmentSoundVolume: number = 0.8;
  26. private weaponSoundVolume: number = 0.8;
  27. // 主音效音量(向后兼容)
  28. private soundEffectVolume: number = 0.8;
  29. // 当前播放的音乐
  30. private currentMusicClip: AudioClip = null;
  31. // Bundle加载器
  32. private bundleLoader: BundleLoader = null;
  33. // 音频缓存
  34. private audioClipCache: Map<string, AudioClip> = new Map();
  35. // 单例实例
  36. private static _instance: AudioManager = null;
  37. start() {
  38. // 设置单例
  39. if (AudioManager._instance === null) {
  40. AudioManager._instance = this;
  41. // 防止场景切换时被销毁
  42. // this.node.parent = null;
  43. // director.addPersistRootNode(this.node);
  44. } else {
  45. this.node.destroy();
  46. return;
  47. }
  48. this.bundleLoader = BundleLoader.getInstance();
  49. this.initializeAudioSources();
  50. }
  51. /**
  52. * 获取单例实例
  53. */
  54. public static getInstance(): AudioManager {
  55. return AudioManager._instance;
  56. }
  57. /**
  58. * 初始化音频源
  59. */
  60. private initializeAudioSources() {
  61. console.log('[AudioManager] 开始初始化音频源');
  62. // 如果没有指定音频源,尝试自动创建
  63. if (!this.musicAudioSource) {
  64. console.log('[AudioManager] 创建音乐播放器AudioSource');
  65. const musicNode = new Node('MusicAudioSource');
  66. musicNode.parent = this.node;
  67. this.musicAudioSource = musicNode.addComponent(AudioSource);
  68. this.musicAudioSource.loop = true;
  69. console.log('[AudioManager] 音乐播放器AudioSource创建完成');
  70. } else {
  71. console.log('[AudioManager] 音乐播放器AudioSource已存在');
  72. }
  73. if (!this.uiSoundAudioSource) {
  74. console.log('[AudioManager] 创建UI音效播放器AudioSource');
  75. const uiSfxNode = new Node('UISoundAudioSource');
  76. uiSfxNode.parent = this.node;
  77. this.uiSoundAudioSource = uiSfxNode.addComponent(AudioSource);
  78. this.uiSoundAudioSource.loop = false;
  79. }
  80. if (!this.enemySoundAudioSource) {
  81. const enemySfxNode = new Node('EnemySoundAudioSource');
  82. enemySfxNode.parent = this.node;
  83. this.enemySoundAudioSource = enemySfxNode.addComponent(AudioSource);
  84. this.enemySoundAudioSource.loop = false;
  85. }
  86. if (!this.environmentSoundAudioSource) {
  87. const envSfxNode = new Node('EnvironmentSoundAudioSource');
  88. envSfxNode.parent = this.node;
  89. this.environmentSoundAudioSource = envSfxNode.addComponent(AudioSource);
  90. this.environmentSoundAudioSource.loop = false;
  91. }
  92. if (!this.weaponSoundAudioSource) {
  93. const weaponSfxNode = new Node('WeaponSoundAudioSource');
  94. weaponSfxNode.parent = this.node;
  95. this.weaponSoundAudioSource = weaponSfxNode.addComponent(AudioSource);
  96. this.weaponSoundAudioSource.loop = false;
  97. }
  98. console.log('[AudioManager] 音频源初始化完成');
  99. console.log(`[AudioManager] musicAudioSource: ${this.musicAudioSource ? '已创建' : '未创建'}`);
  100. // 设置初始音量
  101. this.updateAllVolumes();
  102. }
  103. /**
  104. * 播放背景音乐
  105. * @param musicPath 音乐资源路径
  106. * @param loop 是否循环播放
  107. */
  108. public async playMusic(musicPath: string, loop: boolean = true) {
  109. if (!this.musicAudioSource) {
  110. console.warn('[AudioManager] 音乐播放器未初始化');
  111. return;
  112. }
  113. try {
  114. // 转换路径格式:从 "data/弹球音效/fight bgm" 转换为 "弹球音效/fight bgm"
  115. const bundlePath = musicPath.replace('data/', '');
  116. const clip = await this.bundleLoader.loadAssetFromBundle<AudioClip>('data', bundlePath, AudioClip);
  117. this.currentMusicClip = clip;
  118. this.musicAudioSource.clip = clip;
  119. this.musicAudioSource.loop = loop;
  120. this.musicAudioSource.play();
  121. console.log(`[AudioManager] 播放音乐: ${musicPath}`);
  122. } catch (error) {
  123. console.error(`[AudioManager] 加载音乐失败: ${musicPath}`, error);
  124. }
  125. }
  126. /**
  127. * 停止背景音乐
  128. */
  129. public stopMusic() {
  130. console.log('[AudioManager] stopMusic方法被调用');
  131. console.log(`[AudioManager] musicAudioSource状态: ${this.musicAudioSource ? '存在' : '不存在'}`);
  132. if (this.musicAudioSource) {
  133. console.log(`[AudioManager] musicAudioSource.playing: ${this.musicAudioSource.playing}`);
  134. console.log(`[AudioManager] currentMusicClip: ${this.currentMusicClip ? this.currentMusicClip.name : '无'}`);
  135. if (this.musicAudioSource.playing) {
  136. this.musicAudioSource.stop();
  137. console.log('[AudioManager] 停止音乐播放');
  138. } else {
  139. console.log('[AudioManager] 音乐未在播放,无需停止');
  140. }
  141. // 清除当前音乐剪辑引用
  142. this.currentMusicClip = null;
  143. this.musicAudioSource.clip = null;
  144. console.log('[AudioManager] 已清除音乐剪辑引用');
  145. } else {
  146. console.warn('[AudioManager] 音乐播放器未初始化,无法停止音乐');
  147. }
  148. }
  149. /**
  150. * 暂停背景音乐
  151. */
  152. public pauseMusic() {
  153. if (this.musicAudioSource && this.musicAudioSource.playing) {
  154. this.musicAudioSource.pause();
  155. console.log('[AudioManager] 暂停音乐播放');
  156. }
  157. }
  158. /**
  159. * 恢复背景音乐
  160. */
  161. public resumeMusic() {
  162. if (this.musicAudioSource && this.currentMusicClip) {
  163. this.musicAudioSource.play();
  164. console.log('[AudioManager] 恢复音乐播放');
  165. }
  166. }
  167. /**
  168. * 播放音效(向后兼容)
  169. * @param sfxPath 音效资源路径
  170. * @param volume 音量(可选,0-1)
  171. */
  172. public playSoundEffect(sfxPath: string, volume?: number) {
  173. this.playUISound(sfxPath, volume);
  174. }
  175. /**
  176. * 播放UI音效
  177. * @param sfxPath 音效资源路径
  178. * @param volume 音量(可选,0-1)
  179. */
  180. public playUISound(sfxPath: string, volume?: number) {
  181. this.playSound(this.uiSoundAudioSource, sfxPath, volume, this.uiSoundVolume, 'UI音效');
  182. }
  183. /**
  184. * 播放敌人音效
  185. * @param sfxPath 音效资源路径
  186. * @param volume 音量(可选,0-1)
  187. */
  188. public playEnemySound(sfxPath: string, volume?: number) {
  189. this.playSound(this.enemySoundAudioSource, sfxPath, volume, this.enemySoundVolume, '敌人音效');
  190. }
  191. /**
  192. * 播放环境音效
  193. * @param sfxPath 音效资源路径
  194. * @param volume 音量(可选,0-1)
  195. */
  196. public playEnvironmentSound(sfxPath: string, volume?: number) {
  197. this.playSound(this.environmentSoundAudioSource, sfxPath, volume, this.environmentSoundVolume, '环境音效');
  198. }
  199. /**
  200. * 播放武器音效
  201. * @param sfxPath 音效资源路径
  202. * @param volume 音量(可选,0-1)
  203. */
  204. public playWeaponSound(sfxPath: string, volume?: number) {
  205. this.playSound(this.weaponSoundAudioSource, sfxPath, volume, this.weaponSoundVolume, '武器音效');
  206. }
  207. /**
  208. * 通用音效播放方法
  209. * @param audioSource 音频源
  210. * @param sfxPath 音效资源路径
  211. * @param volume 音量(可选,0-1)
  212. * @param baseVolume 基础音量
  213. * @param soundType 音效类型(用于日志)
  214. */
  215. private async playSound(audioSource: AudioSource, sfxPath: string, volume: number | undefined, baseVolume: number, soundType: string) {
  216. if (!audioSource) {
  217. console.warn(`[AudioManager] ${soundType}播放器未初始化`);
  218. return;
  219. }
  220. try {
  221. // 去掉.mp3后缀(如果存在)
  222. const cleanPath = sfxPath.endsWith('.mp3') ? sfxPath.slice(0, -4) : sfxPath;
  223. // 检查缓存中是否已有该音频
  224. let clip = this.audioClipCache.get(cleanPath);
  225. if (!clip) {
  226. // 转换路径格式:从 "data/弹球音效/xxx" 转换为 "弹球音效/xxx"
  227. const bundlePath = cleanPath.replace('data/', '');
  228. console.log(`[AudioManager] 从Bundle加载新音效: ${bundlePath}`);
  229. clip = await this.bundleLoader.loadAssetFromBundle<AudioClip>('data', bundlePath, AudioClip);
  230. // 缓存音频资源
  231. this.audioClipCache.set(cleanPath, clip);
  232. console.log(`[AudioManager] 音效已缓存: ${cleanPath}`);
  233. } else {
  234. console.log(`[AudioManager] 使用缓存音效: ${cleanPath}`);
  235. }
  236. // 设置临时音量(如果指定)
  237. const originalVolume = audioSource.volume;
  238. if (volume !== undefined) {
  239. audioSource.volume = volume * baseVolume;
  240. }
  241. audioSource.playOneShot(clip);
  242. // 恢复原始音量
  243. if (volume !== undefined) {
  244. audioSource.volume = originalVolume;
  245. }
  246. console.log(`[AudioManager] 播放${soundType}: ${cleanPath}`);
  247. } catch (error) {
  248. console.error(`[AudioManager] 加载${soundType}失败: ${sfxPath}`, error);
  249. }
  250. }
  251. /**
  252. * 设置音乐音量
  253. * @param volume 音量值(0-1)
  254. */
  255. public setMusicVolume(volume: number) {
  256. this.musicVolume = Math.max(0, Math.min(1, volume));
  257. this.updateMusicVolume();
  258. //console.log(`[AudioManager] 设置音乐音量: ${this.musicVolume}`);
  259. }
  260. /**
  261. * 设置音效音量(向后兼容)
  262. * @param volume 音量值(0-1)
  263. */
  264. public setSoundEffectVolume(volume: number) {
  265. this.soundEffectVolume = Math.max(0, Math.min(1, volume));
  266. this.setUISoundVolume(volume);
  267. //console.log(`[AudioManager] 设置音效音量: ${this.soundEffectVolume}`);
  268. }
  269. /**
  270. * 设置UI音效音量
  271. * @param volume 音量值(0-1)
  272. */
  273. public setUISoundVolume(volume: number) {
  274. this.uiSoundVolume = Math.max(0, Math.min(1, volume));
  275. this.updateUISoundVolume();
  276. }
  277. /**
  278. * 设置敌人音效音量
  279. * @param volume 音量值(0-1)
  280. */
  281. public setEnemySoundVolume(volume: number) {
  282. this.enemySoundVolume = Math.max(0, Math.min(1, volume));
  283. this.updateEnemySoundVolume();
  284. }
  285. /**
  286. * 设置环境音效音量
  287. * @param volume 音量值(0-1)
  288. */
  289. public setEnvironmentSoundVolume(volume: number) {
  290. this.environmentSoundVolume = Math.max(0, Math.min(1, volume));
  291. this.updateEnvironmentSoundVolume();
  292. }
  293. /**
  294. * 设置武器音效音量
  295. * @param volume 音量值(0-1)
  296. */
  297. public setWeaponSoundVolume(volume: number) {
  298. this.weaponSoundVolume = Math.max(0, Math.min(1, volume));
  299. this.updateWeaponSoundVolume();
  300. }
  301. /**
  302. * 设置所有音效音量
  303. * @param volume 音量值(0-1)
  304. */
  305. public setAllSoundVolume(volume: number) {
  306. this.setUISoundVolume(volume);
  307. this.setEnemySoundVolume(volume);
  308. this.setEnvironmentSoundVolume(volume);
  309. this.setWeaponSoundVolume(volume);
  310. this.setSoundEffectVolume(volume);
  311. }
  312. /**
  313. * 获取音乐音量
  314. */
  315. public getMusicVolume(): number {
  316. return this.musicVolume;
  317. }
  318. /**
  319. * 获取音效音量(向后兼容)
  320. */
  321. public getSoundEffectVolume(): number {
  322. return this.soundEffectVolume;
  323. }
  324. /**
  325. * 获取UI音效音量
  326. */
  327. public getUISoundVolume(): number {
  328. return this.uiSoundVolume;
  329. }
  330. /**
  331. * 获取敌人音效音量
  332. */
  333. public getEnemySoundVolume(): number {
  334. return this.enemySoundVolume;
  335. }
  336. /**
  337. * 获取环境音效音量
  338. */
  339. public getEnvironmentSoundVolume(): number {
  340. return this.environmentSoundVolume;
  341. }
  342. /**
  343. * 获取武器音效音量
  344. */
  345. public getWeaponSoundVolume(): number {
  346. return this.weaponSoundVolume;
  347. }
  348. /**
  349. * 更新音乐音量
  350. */
  351. private updateMusicVolume() {
  352. if (this.musicAudioSource) {
  353. this.musicAudioSource.volume = this.musicVolume;
  354. }
  355. }
  356. /**
  357. * 更新UI音效音量
  358. */
  359. private updateUISoundVolume() {
  360. if (this.uiSoundAudioSource) {
  361. this.uiSoundAudioSource.volume = this.uiSoundVolume;
  362. }
  363. }
  364. /**
  365. * 更新敌人音效音量
  366. */
  367. private updateEnemySoundVolume() {
  368. if (this.enemySoundAudioSource) {
  369. this.enemySoundAudioSource.volume = this.enemySoundVolume;
  370. }
  371. }
  372. /**
  373. * 更新环境音效音量
  374. */
  375. private updateEnvironmentSoundVolume() {
  376. if (this.environmentSoundAudioSource) {
  377. this.environmentSoundAudioSource.volume = this.environmentSoundVolume;
  378. }
  379. }
  380. /**
  381. * 更新武器音效音量
  382. */
  383. private updateWeaponSoundVolume() {
  384. if (this.weaponSoundAudioSource) {
  385. this.weaponSoundAudioSource.volume = this.weaponSoundVolume;
  386. }
  387. }
  388. /**
  389. * 更新所有音量
  390. */
  391. private updateAllVolumes() {
  392. this.updateMusicVolume();
  393. this.updateUISoundVolume();
  394. this.updateEnemySoundVolume();
  395. this.updateEnvironmentSoundVolume();
  396. this.updateWeaponSoundVolume();
  397. }
  398. /**
  399. * 静音所有音频
  400. */
  401. public muteAll() {
  402. this.setMusicVolume(0);
  403. this.setAllSoundVolume(0);
  404. }
  405. /**
  406. * 恢复所有音频音量
  407. */
  408. public unmuteAll() {
  409. this.setMusicVolume(0.8);
  410. this.setAllSoundVolume(0.8);
  411. }
  412. /**
  413. * 静音所有音效(保留音乐)
  414. */
  415. public muteAllSounds() {
  416. this.setAllSoundVolume(0);
  417. }
  418. /**
  419. * 恢复所有音效音量(保留音乐)
  420. */
  421. public unmuteAllSounds() {
  422. this.setAllSoundVolume(0.8);
  423. }
  424. /**
  425. * 检查音乐是否正在播放
  426. */
  427. public isMusicPlaying(): boolean {
  428. return this.musicAudioSource && this.musicAudioSource.playing;
  429. }
  430. /**
  431. * 清理音频缓存
  432. */
  433. public clearAudioCache() {
  434. console.log(`[AudioManager] 清理音频缓存,共${this.audioClipCache.size}个音效`);
  435. this.audioClipCache.clear();
  436. }
  437. /**
  438. * 获取缓存状态
  439. */
  440. public getCacheInfo(): {count: number, paths: string[]} {
  441. return {
  442. count: this.audioClipCache.size,
  443. paths: Array.from(this.audioClipCache.keys())
  444. };
  445. }
  446. onDestroy() {
  447. // 清理音频缓存
  448. this.clearAudioCache();
  449. if (AudioManager._instance === this) {
  450. AudioManager._instance = null;
  451. }
  452. }
  453. }
  454. /**
  455. * 音频管理器的静态接口
  456. * 提供便捷的全局访问方法
  457. */
  458. export class Audio {
  459. /**
  460. * 播放背景音乐
  461. */
  462. static playMusic(musicPath: string, loop: boolean = true) {
  463. const manager = AudioManager.getInstance();
  464. if (manager) {
  465. manager.playMusic(musicPath, loop);
  466. }
  467. }
  468. /**
  469. * 播放音效(向后兼容)
  470. */
  471. static playSFX(sfxPath: string, volume?: number) {
  472. const manager = AudioManager.getInstance();
  473. if (manager) {
  474. manager.playSoundEffect(sfxPath, volume);
  475. }
  476. }
  477. /**
  478. * 播放UI音效
  479. */
  480. static playUISound(sfxPath: string, volume?: number) {
  481. const manager = AudioManager.getInstance();
  482. if (manager) {
  483. manager.playUISound(sfxPath, volume);
  484. }
  485. }
  486. /**
  487. * 播放敌人音效
  488. */
  489. static playEnemySound(sfxPath: string, volume?: number) {
  490. const manager = AudioManager.getInstance();
  491. if (manager) {
  492. manager.playEnemySound(sfxPath, volume);
  493. }
  494. }
  495. /**
  496. * 播放环境音效
  497. */
  498. static playEnvironmentSound(sfxPath: string, volume?: number) {
  499. const manager = AudioManager.getInstance();
  500. if (manager) {
  501. manager.playEnvironmentSound(sfxPath, volume);
  502. }
  503. }
  504. /**
  505. * 播放武器音效
  506. */
  507. static playWeaponSound(sfxPath: string, volume?: number) {
  508. const manager = AudioManager.getInstance();
  509. if (manager) {
  510. manager.playWeaponSound(sfxPath, volume);
  511. }
  512. }
  513. /**
  514. * 设置音乐音量
  515. */
  516. static setMusicVolume(volume: number) {
  517. const manager = AudioManager.getInstance();
  518. if (manager) {
  519. manager.setMusicVolume(volume);
  520. }
  521. }
  522. /**
  523. * 设置音效音量(向后兼容)
  524. */
  525. static setSFXVolume(volume: number) {
  526. const manager = AudioManager.getInstance();
  527. if (manager) {
  528. manager.setSoundEffectVolume(volume);
  529. }
  530. }
  531. /**
  532. * 设置UI音效音量
  533. */
  534. static setUISoundVolume(volume: number) {
  535. const manager = AudioManager.getInstance();
  536. if (manager) {
  537. manager.setUISoundVolume(volume);
  538. }
  539. }
  540. /**
  541. * 设置敌人音效音量
  542. */
  543. static setEnemySoundVolume(volume: number) {
  544. const manager = AudioManager.getInstance();
  545. if (manager) {
  546. manager.setEnemySoundVolume(volume);
  547. }
  548. }
  549. /**
  550. * 设置环境音效音量
  551. */
  552. static setEnvironmentSoundVolume(volume: number) {
  553. const manager = AudioManager.getInstance();
  554. if (manager) {
  555. manager.setEnvironmentSoundVolume(volume);
  556. }
  557. }
  558. /**
  559. * 设置武器音效音量
  560. */
  561. static setWeaponSoundVolume(volume: number) {
  562. const manager = AudioManager.getInstance();
  563. if (manager) {
  564. manager.setWeaponSoundVolume(volume);
  565. }
  566. }
  567. /**
  568. * 设置所有音效音量
  569. */
  570. static setAllSoundVolume(volume: number) {
  571. const manager = AudioManager.getInstance();
  572. if (manager) {
  573. manager.setAllSoundVolume(volume);
  574. }
  575. }
  576. /**
  577. * 停止音乐
  578. */
  579. static stopMusic() {
  580. const manager = AudioManager.getInstance();
  581. if (manager) {
  582. manager.stopMusic();
  583. } else {
  584. console.warn('[Audio] AudioManager实例未找到,无法停止音乐');
  585. }
  586. }
  587. /**
  588. * 暂停音乐
  589. */
  590. static pauseMusic() {
  591. const manager = AudioManager.getInstance();
  592. if (manager) {
  593. manager.pauseMusic();
  594. }
  595. }
  596. /**
  597. * 恢复音乐
  598. */
  599. static resumeMusic() {
  600. const manager = AudioManager.getInstance();
  601. if (manager) {
  602. manager.resumeMusic();
  603. }
  604. }
  605. /**
  606. * 静音所有音频
  607. */
  608. static muteAll() {
  609. const manager = AudioManager.getInstance();
  610. if (manager) {
  611. manager.muteAll();
  612. }
  613. }
  614. /**
  615. * 恢复所有音频
  616. */
  617. static unmuteAll() {
  618. const manager = AudioManager.getInstance();
  619. if (manager) {
  620. manager.unmuteAll();
  621. }
  622. }
  623. /**
  624. * 静音所有音效(保留音乐)
  625. */
  626. static muteAllSounds() {
  627. const manager = AudioManager.getInstance();
  628. if (manager) {
  629. manager.muteAllSounds();
  630. }
  631. }
  632. /**
  633. * 恢复所有音效(保留音乐)
  634. */
  635. static unmuteAllSounds() {
  636. const manager = AudioManager.getInstance();
  637. if (manager) {
  638. manager.unmuteAllSounds();
  639. }
  640. }
  641. /**
  642. * 清理音频缓存
  643. */
  644. static clearAudioCache() {
  645. const manager = AudioManager.getInstance();
  646. if (manager) {
  647. manager.clearAudioCache();
  648. }
  649. }
  650. /**
  651. * 获取缓存信息
  652. */
  653. static getCacheInfo(): {count: number, paths: string[]} {
  654. const manager = AudioManager.getInstance();
  655. if (manager) {
  656. return manager.getCacheInfo();
  657. }
  658. return {count: 0, paths: []};
  659. }
  660. }