After calling removeTags(), a call on toString() will display the
old information. Please look at the following code:
import
helliker.id3.*;
import java.io.*;
public class
AdamReader {
public static void main(String args[])
{
AdamReader ar = new AdamReader(args[0]);
}
public
AdamReader(String fileName) {
try {
File file = new
File(fileName);
if (file.canWrite()) {
MP3File
mp3File = new MP3File(file,
MP3File.BOTH_TAGS);
System.out.println("mp3File = " +
mp3File.toString());
if (mp3File.id3v1Exists() &&
!mp3File.id3v2Exists()) {
String genre;
String
title;
String artist;
String album;
String year;
String
comment;
int
track;
mp3File.setTaggingType(MP3File.ID3V1_ONLY);
genre
= mp3File.getGenre();
title = mp3File.getTitle();
artist =
mp3File.getArtist();
album = mp3File.getAlbum();
year =
mp3File.getYear();
comment =mp3File.getComment();
track
= mp3File.getTrack();
// get rid of
v1
mp3File.removeTags(MP3File.ID3V1_ONLY); // ***** called
here
System.out.println("1) id3v1Exists = " +
mp3File.id3v1Exists());
//mp3File = new MP3File(file,
MP3File.ID3V2_ONLY);
System.out.println("2) id3v1Exists =
" + mp3File.id3v1Exists());
// write tags from v1 to
v2
mp3File.setTaggingType(MP3File.ID3V2_ONLY);
if
(genre != null &&
!genre.trim().equals(""))
mp3File.setGenre(genre);
if
(title != null &&
!title.trim().equals(""))
mp3File.setTitle(title);
if
(artist != null &&
!artist.trim().equals(""))
mp3File.setArtist(artist);
if
(album != null &&
!album.trim().equals(""))
mp3File.setAlbum(album);
if
(year != null &&
!year.trim().equals(""))
mp3File.setYear(year);
if
(comment != null &&
!comment.trim().equals(""))
mp3File.setComment(comment);
if
(track >
0)
mp3File.setTrack(track);
mp3File.setUserDefinedText("Ripped
by",
"SL");
mp3File.writeTags();
System.out.println("3)
id3v1Exists = " +
mp3File.id3v1Exists());
System.out.println("mp3File = " +
mp3File.toString()) ;// ***** doesn't exist, but the toString
info is still there
}
} else if (file.isDirectory())
{
System.out.println("directory");
} else
{
System.out.println("File is read-only!");
}
} catch
(Exception e) {
e.printStackTrace();
}
}
}
Logged In: NO
Well, that seems quite normal to me, since the
MP3File.writeTag() function just does what it tells... it
WRITES the tags, it does not read them :) Just have a look
at the source code.
So there are 2 solutions :
* re-read the tags by re-instanciating your MP3File, like
mp3file = new MP3File(file,
MP3File.BOTH_TAGS);
* ask Jon to write a readTag() function or write it
yourself ;)
In my case, I use the first solution which seems better and
easier to code. However, I don't know which one would be
better in terms of performance and optimization.
Anyway, this isn't a bug for me ; it depends on how people
understand the writeTag() function.