package com.mortals.xhx.tts.utils;

import com.mpatric.mp3agic.InvalidDataException;
import com.mpatric.mp3agic.Mp3File;
import com.mpatric.mp3agic.MpegFrame;
import com.mpatric.mp3agic.UnsupportedTagException;
import org.apache.commons.io.FileUtils;

import javax.sound.sampled.*;
import java.io.*;
import java.nio.ByteBuffer;
import java.util.List;

/**
 * @author ZYW
 * @date 2024-08-23 9:19
 */

public class AddMp3Util {

    public static String mergeMp3s( List<String> inputPaths) throws IOException{
        String outputPath = "/tmp/";
        if(System.getProperty("os.name").startsWith("Windows")){  //windows电脑测试路径
            outputPath= "F:\\\\";
        }
        File file = new File(outputPath+"new.mp3");
        if (file.exists()) {
            file.delete();
        }
        FileOutputStream fos = new FileOutputStream(outputPath+"new.mp3");

        byte[] buffer = new byte[4096];
        int length;

        for (String inputPath : inputPaths) {
            ClassLoader classLoader = AddMp3Util.class.getClassLoader();
            InputStream inputStream = classLoader.getResourceAsStream(inputPath);

            while ((length = inputStream.read(buffer)) > 0) {
                fos.write(buffer, 0, length);
            }

            inputStream.close();
        }

        fos.close();
        return outputPath;
    }

}
