public class ID3v1Tag
extends java.lang.Object
This class provides methods for reading and writing the ID3v1 and ID3v1.1 tags. This tag is 128
bytes long, and is found at the end of the .mp3 file as shown below. The format of the tag is very simple, as there are eight fixed length fields. All of the fields
are ISO-8859-1 encoded strings with the exception of the genre and the track fields. The genre is a number which is an index into a predefined
list of music genres
, or categories if you like. For example, a genre value of 1 indicates that the song
is "Classic Rock". Finally, the track is stored within the last byte of the comments field. When the track number is stored there, the tag is
considered to be version ID3v1.1.
|
Modifier and Type | Field and Description |
---|---|
static int |
TAG_SIZE
fixed size (in bytes) of ID3v1 tags
|
Constructor and Description |
---|
ID3v1Tag(java.io.InputStream inputStream,
int tagOffset,
java.lang.String path)
called when reading in an existing ID3v1 tag from an .mp3 file.
|
ID3v1Tag(java.io.RandomAccessFile file)
constructor.
|
Modifier and Type | Method and Description |
---|---|
java.lang.String |
getAlbum()
gets the album on which the song was released.
|
java.lang.String |
getArtist()
gets the artist who recorded the song.
|
java.lang.String |
getComment()
gets the description of the song.
|
byte |
getGenre()
gets the genre of the song.
|
java.lang.String |
getGenreAsString()
gets the genre name according to the predefined list of
music genres . |
java.lang.String |
getTitle()
gets the title of the song.
|
byte |
getTrack()
gets the track number of the song on the album.
|
java.lang.String |
getVersion()
gets the version of the ID3 tag.
|
java.lang.String |
getYear()
gets the year the song was released.
|
void |
setAlbum(java.lang.String album)
sets the album on which the song was released.
|
void |
setArtist(java.lang.String artist)
sets the artist who recorded the song.
|
void |
setComment(java.lang.String comment)
sets the description of the song.
|
void |
setGenre(byte genre)
sets the genre of the song.
|
void |
setTitle(java.lang.String title)
sets the title of the song.
|
void |
setTrack(byte track)
sets the track number of the song on the album.
|
void |
setYear(java.lang.String year)
sets the year the song was released.
|
java.lang.String |
toString()
gets a string representation of the ID3v1 tag showing all of its fields and their values.
|
public static final int TAG_SIZE
public ID3v1Tag(java.io.InputStream inputStream, int tagOffset, java.lang.String path) throws java.io.IOException, ParseException
inputStream
- input stream pointing to the ID3v1 tag in an .mp3 file.tagOffset
- position in the .mp3 file where the ID3v1 tag is found.path
- path to the .mp3 file whose ID3v1 tag we are trying to read.java.io.IOException
- if there is an error reading in the ID3v1 tag from the .mp3 file.ParseException
- if the .mp3 file does not contain an ID3v1 tag.public ID3v1Tag(java.io.RandomAccessFile file) throws java.io.IOException, ParseException
file
- random access file to read in the ID3v1 tag from an .mp3 file.java.io.IOException
- if there is an error while reading the ID3v1 tag.ParseException
- if an ID3v1 tag can not be found or if an invalid value is detected while parsing the ID3v1 tag.public java.lang.String getArtist()
setArtist(String)
public void setArtist(java.lang.String artist)
artist
- the artist who recorded the song.getArtist()
public java.lang.String getTitle()
setTitle(String)
public void setTitle(java.lang.String title)
title
- the title of the song.getTitle()
public java.lang.String getAlbum()
setAlbum(String)
public void setAlbum(java.lang.String album)
album
- the album which contains the song.getAlbum()
public java.lang.String getYear()
setYear(String)
public void setYear(java.lang.String year)
year
- the year the song was released.getYear()
public java.lang.String getComment()
setComment(String)
public void setComment(java.lang.String comment)
comment
- the description of the song.getComment()
public byte getTrack()
setTrack(byte)
public void setTrack(byte track)
track
- the track number of the song on the album.getTrack()
public byte getGenre()
setGenre(byte)
public void setGenre(byte genre)
Genre | description |
---|---|
0. | Blues |
1. | Classic Rock |
2. | Country |
3. | Dance |
4. | Disco |
5. | Funk |
6. | Grunge |
7. | Hip-Hop |
8. | Jazz |
9. | Metal |
10. | New Age |
11. | Oldies |
12. | Other |
13. | Pop |
14. | R&B |
15. | Rap |
16. | Reggae |
17. | Rock |
18. | Techno |
19. | Industrial |
20. | Alternative |
21. | Ska |
22. | Death Metal |
23. | Pranks |
24. | Soundtrack |
25. | Euro-Techno |
26. | Ambient |
27. | Trip-Hop |
28. | Vocal |
29. | Jazz+Funk |
30. | Fusion |
31. | Trance |
32. | Classical |
33. | Instrumental |
34. | Acid |
35. | House |
36. | Game |
37. | Sound Clip |
38. | Gospel |
39. | Noise |
40. | AlternRock |
41. | Bass |
42. | Soul |
43. | Punk |
44. | Space |
45. | Meditative |
46. | Instrumental Pop |
47. | Instrumental Rock |
48. | Ethnic |
49. | Gothic |
50. | Darkwave |
51. | Techno-Industrial |
52. | Electronic |
53. | Pop-Folk |
54. | Eurodance |
55. | Dream |
56. | Southern Rock |
57. | Comedy |
58. | Cult |
59. | Gangsta |
60. | Top 40 |
61. | Christian Rap |
62. | Pop/Funk |
63. | Jungle |
64. | Native American |
65. | Cabaret |
66. | New Wave |
67. | Psychadelic |
68. | Rave |
69. | Showtunes |
70. | Trailer |
71. | Lo-Fi |
72. | Tribal |
73. | Acid Punk |
74. | Acid Jazz |
75. | Polka |
76. | Retro |
77. | Musical |
78. | Rock & Roll |
79. | Hard Rock |
genre
- the genre of the song.getGenre()
public java.lang.String getGenreAsString()
music genres
.public java.lang.String getVersion()
public java.lang.String toString()
toString
in class java.lang.Object