/** * sets the synchronized lyrics/text. * * @param synchronizedLyrics the synchronized lyrics/text. * @see #getSynchronizedLyrics() */ public void setSynchronizedLyrics(List<SynchronizedLyric> synchronizedLyrics) { int previousTimeStamp = -1; for (SynchronizedLyric synchronizedLyric : synchronizedLyrics) { if (synchronizedLyric.getTimeStamp() > previousTimeStamp) previousTimeStamp = synchronizedLyric.getTimeStamp(); else throw new IllegalArgumentException( "The time stamps in the synchronized lyrics in the " + frameType.getId() + " frame must be in ascending chronological order."); } this.synchronizedLyrics = synchronizedLyrics; this.dirty = true; }
/** * If the frame body's values have been modified, then resize the raw binary buffer and store the * new values there. When finished, the dirty flag is reset to indicate that the buffer is up to * date, and the frame is now ready to be saved to the .mp3 file. */ @Override public void setBuffer() { if (isDirty()) { int numSynchronizedLyricBytes = 0; for (SynchronizedLyric synchronizedLyric : synchronizedLyrics) numSynchronizedLyricBytes += stringToBytes(encoding, synchronizedLyric.getText()).length + 4; byte[] languageBytes = language.getCodeBytes(); byte[] descriptionBytes = stringToBytes(encoding, description); byte[] synchronizedLyricBytes = new byte[numSynchronizedLyricBytes]; byte[] textBytes = null; byte[] timeStampBytes = null; int index = 0; buffer = new byte [1 + languageBytes.length + 1 + 1 + descriptionBytes.length + synchronizedLyricBytes.length]; buffer[index] = (byte) encoding.ordinal(); index = 1; System.arraycopy(languageBytes, 0, buffer, index, languageBytes.length); index += languageBytes.length; buffer[index] = (byte) timeStampFormat.getValue(); index++; buffer[index] = (byte) contentType.ordinal(); index++; System.arraycopy(descriptionBytes, 0, buffer, index, descriptionBytes.length); index += descriptionBytes.length; for (SynchronizedLyric synchronizedLyric : synchronizedLyrics) { numSynchronizedLyricBytes += stringToBytes(encoding, synchronizedLyric.getText()).length + 4; textBytes = stringToBytes(encoding, synchronizedLyric.getText()); System.arraycopy(textBytes, 0, buffer, index, textBytes.length); index += textBytes.length; timeStampBytes = intToBytes(synchronizedLyric.getTimeStamp()); System.arraycopy(timeStampBytes, 0, buffer, index, timeStampBytes.length); index += timeStampBytes.length; } dirty = false; } }