import Player from 'xgplayer'
import { globalStore } from '@/stores'
const OSS_URL = import.meta.env.VITE_OSS_URL

const soundUrl = `${OSS_URL}/xuexiaole_clinet/sound/`

const useAudio = function () {
  // 每个音频生成一个对应的 isPlay 状态
  function play(url: string) {
    const { system } = globalStore()
    const player = new Player({
      url: soundUrl + url,
      id: 'learn-audio',
      autoplay: true,
      keyShortcut: false,
      volume: system.volume.musicVolume / 100,
    })
    player.play()
  }
  return {
    play,
  }
}

export default useAudio
