import extend from "./extend";
import Voice from "./voice";

/**
 * 提示音
 */
class Tone {
    /**
     * 声音路径
     */
    voicePath = {
        /**
         * 文件路径 Ding 
         */
        ding: '/static/voices/Windows Ding.wav'
    };

    /**
     * 播放
     * @param {string} filePath 音频文件路径
     */
    play(filePath) {
        try {
            let voice = new Voice(filePath);
            voice.onCanplay(res => {
                voice.play();
            });
            voice.onEnded(res => {
                voice.destroy();
                voice = null;
            });
        } catch (ex) {
            console.error('Tone Play Error：', ex);
        }
    }

    /**
     * 播放 Ding
     */
    playDing() {
        this.play(this.voicePath.ding);
        // this.voices.ding.play();
    }
}

/**
 * 提示音
 */
export default Tone;