Adding Cover Art to downloaded mp3 on Android

女生的网名这么多〃 提交于 2019-12-02 21:00:04

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); 

You Will need also the Jakarta Regex jar

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();
    }
}

Got it from stackOverflow , dont know from who :)

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!