Commit 415761c3 authored by 周亚武's avatar 周亚武

修改合并mp3文件规则

parent 8228ad1d
package com.mortals.xhx.tts.utils; package com.mortals.xhx.tts.utils;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.springframework.core.io.ClassPathResource;
import java.io.*; import java.io.*;
import java.util.List; import java.util.List;
...@@ -20,12 +21,12 @@ public class SpliceMp3Util { ...@@ -20,12 +21,12 @@ public class SpliceMp3Util {
ClassLoader classLoader = SpliceMp3Util.class.getClassLoader(); ClassLoader classLoader = SpliceMp3Util.class.getClassLoader();
InputStream inputStream = classLoader.getResourceAsStream(path); InputStream inputStream = classLoader.getResourceAsStream(path);
String fileName = path.substring(path.lastIndexOf("/")+1); String fileName = path.substring(path.lastIndexOf("/")+1);
File file = new File(lujing+fileName); File file = new File(lujing+fileName);
//转换 File file1 = new File(lujing+fileName + "01");// 分离ID3V2后的文件,这是个中间文件,最后要被删除
FileUtils.copyInputStreamToFile(inputStream, file); File file2 = new File(lujing+fileName + "001");// 分离id3v1后的文件
File file1 = new File(file.getAbsolutePath() + "01");// 分离ID3V2后的文件,这是个中间文件,最后要被删除
File file2 = new File(file.getAbsolutePath() + "001");// 分离id3v1后的文件
RandomAccessFile rf = new RandomAccessFile(file, "rw");// 随即读取文件 RandomAccessFile rf = new RandomAccessFile(file, "rw");// 随即读取文件
copyInputStreamToRandomAccessFile(inputStream,rf);
FileOutputStream fos = new FileOutputStream(file1); FileOutputStream fos = new FileOutputStream(file1);
byte ID3[] = new byte[3]; byte ID3[] = new byte[3];
rf.read(ID3); rf.read(ID3);
...@@ -96,6 +97,14 @@ public class SpliceMp3Util { ...@@ -96,6 +97,14 @@ public class SpliceMp3Util {
} }
public static void copyInputStreamToRandomAccessFile(InputStream inputStream,RandomAccessFile randomAccessFile) throws IOException {
byte[] buffer = new byte[1024];
int bytesRead;
while ((bytesRead = inputStream.read(buffer)) != -1) {
randomAccessFile.write(buffer, 0, bytesRead);
}
}
/** /**
* 返回合并后的文件的路径名,默认放在第一个文件的目录下 * 返回合并后的文件的路径名,默认放在第一个文件的目录下
* @return * @return
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment