I'm trying to programatically set the ID3 tags of some mp3s. After having gave up the jaudiotagger I found the MyID3 library http://www.fightingquaker.com/myid3/
I'm by no means an experienced Java programmer, but I have some knowledge of OOP. I managed to get as far as writing a class, everything works well, except for a strange error, that I can't understand. My class is:
import org.cmc.music.myid3.*;
import org.cmc.music.metadata.*;
import java.io.*;
import java.lang.*;
/**
* The HelloWorldApp class implements an application that
* simply prints "Hello World!" to standard output.
*/
class lrsetid3 {
public static void main(String[] args) {
String files;
File inputfolder = new File("c:\\ID3\\input");
File[] listOfFiles = inputfolder.listFiles();
for (int i = 0; i < listOfFiles.length; i++)
{
if (listOfFiles[i].isFile())
{
// files = listOfFiles[i].getName();
}
try {
MusicMetadataSet src_set = new MyID3().read(listOfFiles[i]);
IMusicMetadata metadata = src_set.getSimplified();
String artist = metadata.getArtist();
metadata.setArtist("Bob Marley");
System.out.println(listOfFiles[i].getName());
File src = new File ("c:\\ID3\\input" + listOfFiles[i].getName());
System.out.println(listOfFiles[i].isFile());
System.out.println(listOfFiles[i].exists());
File dst = new MyID3().write(src, dst, src_set, metadata);
// System.out.println("Artist" + artist); // Display the string.
}
catch (Exception e){
e.printStackTrace();
}
}
}
And the error that I get is on the line: File dst = new MyID3().write(src, dst, src_set, metadata);
lrsetid3.java:37: error: incompatible types
File dst = new MyID3().write(src, dst, src_set, metadata);
^
required: File
found: void
1 error
The weird part is that the printouts say that the first parameter of the write function is a File... I do not get why the compiler does not want to accept src as a File variable.
Many thanks for your help
that will return a new MyID3 object.
File dst = new MyID3();
This however, will return what the write() method returns. In this case void. (I presume)
File dst = new MyID3().write(src, dst, src_set, metadata);
To fix it, do this:
File dst = new MyID3();
dst.write(src, dst, src_set, metadata);
And of course, the same rule applies to this line:
MusicMetadataSet src_set = new MyID3().read(listOfFiles[i]);