audioUtil.js 447 B

1234567891011121314151617181920
  1. import { ref } from "vue";
  2. // 创建音频上下文引用
  3. const audioContext = ref(null);
  4. // 初始化音频
  5. export const initClickSound = () => {
  6. audioContext.value = uni.createInnerAudioContext();
  7. audioContext.value.src = "/static/bap.mp3";
  8. audioContext.value.volume = 0.8;
  9. };
  10. // 播放点击音效
  11. export const playClickSound = () => {
  12. // #ifdef APP-PLUS
  13. if (audioContext.value) {
  14. audioContext.value.play();
  15. }
  16. // #endif
  17. };