下载这个 jar 文件MyID3_for_android并将其添加到项目的构建路径中。这是如何更改封面的示例代码
File src = new File("filepath");
MusicMetadataSet src_set = new MyID3().read(src);
File img = (new File("imagePath"));
Vector<ImageData> fileList = new Vector<ImageData>();
ImageData data = new ImageData(readFile(img), "", "", 3);
fileList.add(data);
MusicMetadata metadata = (MusicMetadata) src_set.getSimplified();
metadata.setPictureList(fileList);
File dst = new File("destinationPath");
new MyID3().write(src, dst, src_set, metadata);
您还需要Jakarta Regex jar
readFile 只是一个从 File 中获取 byte[] 的函数
public static byte[] readFile (File file) throws IOException {
// Open file
RandomAccessFile f = new RandomAccessFile(file, "r");
try {
// Get and check length
long longlength = f.length();
int length = (int) longlength;
if (length != longlength) throw new IOException("File size >= 2 GB");
// Read file and return data
byte[] data = new byte[length];
f.readFully(data);
return data;
}
finally {
f.close();
}
}
从 stackOverflow 得到它,不知道从谁:)