1

I'm trying to find out how to list the music on my computer by a certain artist. I understand how to list all the music in the directory but I can't find a way to show only the music from one of the artists. Below is the code I'm using to list all the music in the directory.

How do I search the meta data for the artist's name and filter those files? Feel free to comment on the code if that's not a good way to list the files, I'm pretty new to all of this.

Code Fragment:

File musicList = new File("C:\\Users\\Music");
String[] fileNames = musicList.list();
String songsResponse = "";

int number = 1;
for(int i = 0; i < fileNames.length; i++)
{
    if(fileNames[i].endsWith(".mp3"))
    {
        songsResponse += (number + ". ") + fileNames[i] + "\n";
        number++;
    }
}
4

2 回答 2

2

You could also try Java ID3 Tag Library, which supports ID3v1, ID3v1.1, Lyrics3v1, Lyrics3v2, ID3v2.2, ID3v2.3, and ID3v2.4 tags as well as reading MP3 Frame Headers:

private void printArtistFromMp3() {
    final String DIRECTORY = "C:\\Freek\\Dropbox\\Freek\\Muziek\\Queens of the Stone Age\\2000 - R\\";
    try {
        final MP3File mp3File = new MP3File(DIRECTORY + "01-Feel good hit of the summer.mp3");
        if (mp3File.hasID3v1Tag())
            System.out.println("Artist (ID3v1 tag): " + mp3File.getID3v1Tag().getArtist());
        if (mp3File.hasID3v2Tag())
            System.out.println("Lead artist (ID3v2 tag): " + mp3File.getID3v2Tag().getLeadArtist());
    } catch (IOException e) {
        e.printStackTrace();
    } catch (TagException e) {
        e.printStackTrace();
    }
}

The code above printed "Lead artist (ID3v2 tag): Queens of the Stone Age" on my laptop.

于 2013-03-30T21:59:02.283 回答
1

Take a look at Jaudiotagger:

  • Supports MP3 ID3v1,ID3v11, ID3v2.2, v2.3 and v2.4 are transparently
于 2013-03-30T21:53:12.470 回答