как добавить обложку в mp3 файл в Android - PullRequest
0 голосов
/ 15 января 2019

Как я могу изменить или добавить обложку к mp3-файлу в Android?

Я использовал этот ответ , но вывод не может быть воспроизведен. это мой код:

  File f = new File(Environment.getExternalStorageDirectory(), "stage");
    if (!f.exists()) {
        f.mkdirs();
    }
    File src = new File(Environment.getExternalStorageDirectory() + "/" + "stage", "music" + ".mp3");

    MusicMetadataSet src_set = null;
    try {
        src_set = new MyID3().read(src);
    } catch (IOException e) {
        e.printStackTrace();
    }

    String completePath1 = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS) + "/"+ "img.jpg";
    File img = new File(completePath1);

    Vector<ImageData> fileList = new Vector<ImageData>();
    ImageData data = null;
    try {
        data = new ImageData(readFile(img), "", "", 3);
    } catch (IOException e) {
        e.printStackTrace();
    }
    fileList.add(data);

    MusicMetadata metadata =  (MusicMetadata) src_set.getSimplified();
    metadata.setPictureList(fileList);

    File dst = new File(Environment.getExternalStorageDirectory() + "/" + "stage", "output" + ".mp3");

    try {
        new MyID3().write(src, dst, src_set, metadata);
    } catch (IOException e) {
        e.printStackTrace();
    } catch (ID3WriteException e) {
        e.printStackTrace();
    }

и метод readFile:

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

Я использую в своем коде библиотеку MyID3_for_android и Jararta Regex jar . Есть ли другой способ сделать эту работу?

...