audioUtil.js 431 B

123456789101112131415161718
  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. if (audioContext.value) {
  13. audioContext.value.play();
  14. }
  15. };