package com.zhili.stationcontrol.tts.util;

import lombok.extern.slf4j.Slf4j;

import javax.swing.*;
import java.applet.Applet;
import java.applet.AudioClip;
import java.io.File;
import java.net.URL;

/**
 * @author ：HuangBin
 * @description：TODO
 * @date ：2023/5/18 16:30
 */
@Slf4j
public class WavPlayUtil extends JFrame {

    public static void play(String path) {
        try {
            URL cb;
            File f = new File(path); //引号里面的是音乐文件所在的绝对路径
            cb = f.toURL();
            AudioClip aau;
            aau = Applet.newAudioClip(cb);//加载音频
            aau.play(); //播放音频
            System.out.println(path + "，播放完成");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void play1(String path) {
        try {
            Process exec = Runtime.getRuntime().exec("play " + path);
            exec.waitFor();
            System.out.println(path + "，播放完成");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void play2(String path, Integer vol) {
//        "play -v " + Float.valueOf(new Integer(vol).toString()) / 100 + " " + path
        Float v = Float.valueOf(new Integer(vol).toString()) / 100;
        log.info("real v:{}", v);
        try {
            Process exec = Runtime.getRuntime().exec("play -v " + v.toString() + " " + path);
            exec.waitFor();
            System.out.println(path + "，播放完成");
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}
