Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problem with getAlbumImage () #27

Closed
srBruning opened this issue May 13, 2013 · 5 comments
Closed

problem with getAlbumImage () #27

srBruning opened this issue May 13, 2013 · 5 comments

Comments

@srBruning
Copy link

when using this method returns null for me all the songs that I try even knowing that they have cover

public Musica getMusica(String path) {

    Musica musica = new Musica();
    // caminho
    musica.setCaminho(path);
    Mp3File mp3file;
    try {
        mp3file = new Mp3File(path);
        // duração
        musica.setDuracao((int) mp3file.getLengthInSeconds());

        if (mp3file.hasId3v1Tag()) {
                      //load the data in the object Musica
                    } else if (mp3file.hasId3v2Tag()) {
            ID3v2 id3v2Tag = mp3file.getId3v2Tag();

            //load the data in the object Musica

            byte[] imageData = id3v2Tag.getAlbumImage();

            if (imageData != null) {
                Image img = ImageIO
                        .read(new ByteArrayInputStream(imageData));
                musica.setImage(img);



            }
        } else throw new UnsupportedTagException();

    } catch (UnsupportedTagException e) {

        musica.setArtista("Desconhecido");
        musica.setAlbum("Desconhecido");
        musica.setTitulo(path.substring(path.lastIndexOf("\\") + 1,
                path.lastIndexOf(".") - 1));
        musica.setGenero("Desconhecido");

    } catch (InvalidDataException | IOException e) {
        System.out.println("kk");
        return null;
    }

    return musica;

}
@beckchr
Copy link
Contributor

beckchr commented May 17, 2013

Probably both of mp3file.hasId3v1Tag() and mp3file.hasId3v2Tag() return true for id3v2 tagged files...

@mpatric
Copy link
Owner

mpatric commented May 17, 2013

Are you using the latest version of mp3agic? If the album image description is unicode, it sounds like it might be related to a bug that was fixed in commit ec069e0. Please try the latest version to see if it works for you.

@beckchr
Copy link
Contributor

beckchr commented May 23, 2013

Just swap if/else branches, i.e ask for mp3file.hasId3v2Tag() first.

@mpatric
Copy link
Owner

mpatric commented May 23, 2013

@srBruning - for mp3s that have both an ID3v1 and ID3v2 tag, you'll probably want to use the ID3v2, or use what you can from it, and fall back to the ID3v1 for missing/blank fields in the ID3v2.

As your code stands, for an mp3 with both an ID3v1 and ID3v2 tag, the code that extracts the album image will never be called.

@mpatric mpatric closed this as completed May 23, 2013
@srBruning
Copy link
Author

Thank you. Worked. had to change the conditional to first check if id3v2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants