private int maxEndOffset() { int maxEndOffset = (int) getLength(); if (hasId3v1Tag()) maxEndOffset -= ID3v1Tag.TAG_LENGTH; return maxEndOffset; }
private void initCustomTag(SeekableByteChannel seekableByteChannel) throws IOException { int bufferLength = (int) (getLength() - (endOffset + 1)); if (hasId3v1Tag()) bufferLength -= ID3v1Tag.TAG_LENGTH; if (bufferLength <= 0) { customTag = null; } else { ByteBuffer byteBuffer = ByteBuffer.allocate(bufferLength); seekableByteChannel.position(endOffset + 1); byteBuffer.clear(); int bytesRead = seekableByteChannel.read(byteBuffer); customTag = byteBuffer.array(); if (bytesRead < bufferLength) throw new IOException("Not enough bytes read"); } }
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(); } }
private int maxEndOffset() { int maxEndOffset = (int) getLength(); if (hasId3v1Tag()) maxEndOffset -= ID3v1Tag.TAG_LENGTH; return maxEndOffset; }
private void initCustomTag(SeekableByteChannel seekableByteChannel) throws IOException { int bufferLength = (int) (getLength() - (endOffset + 1)); if (hasId3v1Tag()) bufferLength -= ID3v1Tag.TAG_LENGTH; if (bufferLength <= 0) { customTag = null; } else { ByteBuffer byteBuffer = ByteBuffer.allocate(bufferLength); seekableByteChannel.position(endOffset + 1); byteBuffer.clear(); int bytesRead = seekableByteChannel.read(byteBuffer); customTag = byteBuffer.array(); if (bytesRead < bufferLength) throw new IOException("Not enough bytes read"); } }
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(); } }
String path = jfc.getSelectedFile().getPath(); mp3file = new Mp3File(path); if (mp3file!=null && mp3file.hasId3v1Tag()) { ID3v1 id3v1Tag = mp3file.getId3v1Tag(); System.out.println("Track: " + id3v1Tag.getTrack());
protected Mp3Retag(String filename) { try { mp3file = new Mp3File(filename); boolean hasId3v1Tag = mp3file.hasId3v1Tag(); boolean hasId3v2Tag = mp3file.hasId3v2Tag(); boolean hasImage = false;
System.out.println("Bitrate: " + mp3file.getBitrate() + " kbps " + (mp3file.isVbr() ? "(VBR)" : "(CBR)")); 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")); if (mp3file.hasId3v1Tag()) { ID3v1 id3v1Tag = mp3file.getId3v1Tag(); System.out.println("Track: " + id3v1Tag.getTrack()); if (mp3file.hasId3v1Tag()) { id3v1Tag = mp3file.getId3v1Tag(); } else {
Mp3File mp3file = new Mp3File("SomeMp3File.mp3"); ID3v1 id3v1Tag; if (mp3file.hasId3v1Tag()) { id3v1Tag = mp3file.getId3v1Tag(); } else { // mp3 does not have an ID3v1 tag, let's create one.. id3v1Tag = new ID3v1Tag(); mp3file.setId3v1Tag(id3v1Tag); } id3v1Tag.setTrack("5"); id3v1Tag.setArtist("An Artist"); id3v1Tag.setTitle("The Title"); id3v1Tag.setAlbum("The Album"); id3v1Tag.setYear("2001"); id3v1Tag.setGenre(12); id3v1Tag.setComment("Some comment"); mp3file.save("MyMp3File.mp3");