import java.io.File;
import java.io.IOException;
import com.beaglebuddy.mp3.MP3;
import com.beaglebuddy.id3.enums.PictureType;
public class SampleCode
{
public static void main(String[] args)
{
try
{
MP3 mp3 = new MP3("C:/mp3/hells bells.mp3");
// if there was any invalid information (ie, ID3v2.x frames) in the .mp3 file,
// then display the errors to the user
if (mp3.hasErrors())
{
mp3.displayErrors(System.out); // display the errors that were found
mp3.save(); // discard the invalid information (ID3v2.x frames) and
} // save only the valid frames back to the .mp3 file
if (mp3.getAudioDuration() == 0) // if the length of the song hasn't been specified,
mp3.setAudioDuration(); // then calculate it from the mpeg audio frames
// print out all the internal information about the .mp3 file
System.out.println(mp3);
// get some specific information about the song
System.out.println("audio duration.....: " + mp3.getAudioDuration() + " s\n" +
"audio size.........: " + mp3.getAudioSize() + " bytes\n" +
"album..............: " + mp3.getAlbum() + "\n" +
"artist.............: " + mp3.getBand() + "\n" +
"contributing artist: " + mp3.getLeadPerformer() + "\n" +
"lyrics by..........: " + mp3.getLyricsBy() + "\n" +
"music by...........: " + mp3.getMusicBy() + "\n" +
"picture............: " + mp3.getPicture(PictureType.FRONT_COVER) + "\n" +
"publisher..........: " + mp3.getPublisher() + "\n" +
"rating.............: " + mp3.getRating() + "\n" +
"title..............: " + mp3.getTitle() + "\n" +
"track #............: " + mp3.getTrack() + "\n" +
"year recorded......: " + mp3.getYear() + "\n" +
"lyrics.............: " + mp3.getLyrics() + "\n");
mp3.setBand("AC DC");
mp3.setAlbum("Back In Black");
mp3.setTitle("Hells Bells");
mp3.setMusicType(Genre.HARD_ROCK); // Hard Rock == (79)
mp3.setTrack(1); // 1st song on the cd
mp3.setYear(1980); // released in 1980
mp3.setAudioDuration(310); // 310 seconds == 5 minutes and 10 seconds
mp3.setRating(240); // 1= worst, 255 = best
mp3.setLyrics("I'm rolling thunder\npouring rain.\nI'm coming on like a hurricane\n...");
mp3.setPicture(PictureType.FRONT_COVER, new File("c:/images/ac_dc/back_in_black.jpg"));
mp3.save();
}
catch (IOException ex)
{
System.out.println("An error occurred while reading/saving the mp3 file.");
ex.printStackTrace();
}
}
}
|