在Android上将Cover Art添加到下载的mp3 [英] Adding Cover Art to downloaded mp3 on Android
问题描述
如何以编程方式向下载的mp3添加封面(专辑封面)?
How do I add a cover art (album art) to a downloaded mp3 programmatically?
我让我的应用通过Android APIS中的DownloadManager下载mp3文件,如下所示:
I am letting my app download a mp3 file via the DownloadManager from the Android APIS as shown below:
private void startDownload(){
Uri uri = Uri.parse(BASE_URL+DOWNLOAD+mp3+".mp3");
filename = title+".mp3";
Request request = new DownloadManager.Request(uri)
.setDestinationInExternalPublicDir(MUSIC_PATH, filename);
DOWNLOAD_MANAGER.enqueue(request);
}
是否可以在下载的mp3文件中添加Coverart,以便手机上的mp3播放器在播放歌曲时显示图像?
Is it possible to add a coverart to the downloaded mp3 file, so that the mp3 player on the phone will show a image while playing the song?
推荐答案
Download this jar file MyID3_for_android and add it to your project's build path. here is a sample code of how you can change the cover
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);
您还需要雅加达正则表达式jar
readFile仅仅是从File获取byte []的函数
readFile is only a function to get byte[] from File
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那里得到它,不知道来自谁:)
Got it from stackOverflow , dont know from who :)
这篇关于在Android上将Cover Art添加到下载的mp3的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!