Mp3File song = new Mp3File(filename); if (song.hasId3v2Tag()){ ID3v2 id3v2tag = song.getId3v2Tag(); byte[] imageData = id3v2tag.getAlbumImage(); //converting the bytes to an image BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageData)); }
public void save(String newFilename) throws IOException, NotSupportedException { if (path.toAbsolutePath().compareTo(Paths.get(newFilename).toAbsolutePath()) == 0) { throw new IllegalArgumentException("Save filename same as source filename"); } try (SeekableByteChannel saveFile = Files.newByteChannel(Paths.get(newFilename), EnumSet.of(StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE))) { if (hasId3v2Tag()) { ByteBuffer byteBuffer = ByteBuffer.wrap(id3v2Tag.toBytes()); byteBuffer.rewind(); saveFile.write(byteBuffer); } saveMpegFrames(saveFile); if (hasCustomTag()) { ByteBuffer byteBuffer = ByteBuffer.wrap(customTag); byteBuffer.rewind(); saveFile.write(byteBuffer); } if (hasId3v1Tag()) { ByteBuffer byteBuffer = ByteBuffer.wrap(id3v1Tag.toBytes()); byteBuffer.rewind(); saveFile.write(byteBuffer); } saveFile.close(); } }
Mp3File song = new Mp3File(filename); if (song.hasId3v2Tag()){ ID3v2 id3v2tag = song.getId3v2Tag(); byte[] imageData = id3v2tag.getAlbumImage(); //converting the bytes to an image BufferedImage img = ImageIO.read(new ByteArrayInputStream(imageData)); }
Mp3File mp3file = new Mp3File("SomeMp3File.mp3"); System.out.println("Length of this mp3 in seconds is: " + mp3file.getLengthInSeconds()); if(mp3file.hasId3v2Tag()) { ID3v2 id3v2tag = mp3file.getId3v2Tag(); System.out.println("The artist in the ID3v2 tag is: " + id3v2tag.getArtist()); id3v2tag.setArtist("A new artist"); mp3file.save("ASavedMp3File.mp3"); System.out("Saved mp3 file with new name and artist set to 'A new artist'"); }
public void save(String newFilename) throws IOException, NotSupportedException { if (path.toAbsolutePath().compareTo(Paths.get(newFilename).toAbsolutePath()) == 0) { throw new IllegalArgumentException("Save filename same as source filename"); } try (SeekableByteChannel saveFile = Files.newByteChannel(Paths.get(newFilename), EnumSet.of(StandardOpenOption.CREATE, StandardOpenOption.TRUNCATE_EXISTING, StandardOpenOption.WRITE))) { if (hasId3v2Tag()) { ByteBuffer byteBuffer = ByteBuffer.wrap(id3v2Tag.toBytes()); byteBuffer.rewind(); saveFile.write(byteBuffer); } saveMpegFrames(saveFile); if (hasCustomTag()) { ByteBuffer byteBuffer = ByteBuffer.wrap(customTag); byteBuffer.rewind(); saveFile.write(byteBuffer); } if (hasId3v1Tag()) { ByteBuffer byteBuffer = ByteBuffer.wrap(id3v1Tag.toBytes()); byteBuffer.rewind(); saveFile.write(byteBuffer); } saveFile.close(); } }
Mp3File mp3file = new Mp3File("example.mp3"); ID3v2 id3v2Tag; if (mp3file.hasId3v2Tag()) { id3v2Tag = mp3file.getId3v2Tag(); } else { id3v2Tag = new ID3v24Tag(); mp3file.setId3v2Tag(id3v2Tag); } id3v2Tag.clearAlbumImage(); mp3file.save("example.mp3");
mp3file = new Mp3File(filename); boolean hasId3v1Tag = mp3file.hasId3v1Tag(); boolean hasId3v2Tag = mp3file.hasId3v2Tag(); boolean hasImage = false; if (hasId3v2Tag && mp3file.getId3v2Tag().getAlbumImage() != null) hasImage = true;
System.out.println("Sample rate: " + mp3file.getSampleRate() + " Hz"); System.out.println("Has ID3v1 tag?: " + (mp3file.hasId3v1Tag() ? "YES" : "NO")); System.out.println("Has ID3v2 tag?: " + (mp3file.hasId3v2Tag() ? "YES" : "NO")); System.out.println("Has custom tag?: " + (mp3file.hasCustomTag() ? "YES" : "NO")); mp3file.save("MyMp3File.mp3"); if (mp3file.hasId3v2Tag()) { ID3v2 id3v2Tag = mp3file.getId3v2Tag(); System.out.println("Track: " + id3v2Tag.getTrack()); if (mp3file.hasId3v2Tag()) { ID3v2 id3v2Tag = mp3file.getId3v2Tag(); byte[] imageData = id3v2Tag.getAlbumImage(); if (mp3file.hasId3v2Tag()) { id3v2Tag = mp3file.getId3v2Tag(); } else {