public class MP3Base extends MP3BaseID3v24
![]() |
![]() |
This base class provides some underlying methods that help make the derived MP3 class's interface much cleaner and easier to understand. Thus, this class provides lower level methods that are used by the MP3 class, but would otherwise clutter the MP3 class's public interface.
Modifier and Type | Field and Description |
---|---|
protected long |
audioSize
size (in bytes) of the audio portion of the .mp3 file.
|
protected int |
bitrate
|
protected BitrateType |
bitrateType
|
protected long |
fileSize
size (in bytes) of the .mp3 file.
|
protected java.io.File |
mp3File
if the mp3 file is loaded from a local file, then this data member will contain the path to the .mp3 file.
|
protected java.net.URL |
mp3Url
if the mp3 file is loaded from a URL, then this data member will contain the URL to the .mp3 file.
|
protected MPEGFrame |
mpegFrame
the 1st mpeg audio frame found after the end of the ID3v2.x tag.
|
protected long |
tagSize
size (in bytes) of the ID3v2.x tag.
|
id3v24Tag
id3v23Tag
Constructor and Description |
---|
MP3Base(java.io.File mp3File)
constructor.
|
MP3Base(java.lang.String mp3File)
constructor.
|
MP3Base(java.net.URL mp3Url)
constructor.
|
Modifier and Type | Method and Description |
---|---|
protected int |
calculateAudioDuration()
calculates the duration of the song (in seconds) from data found in the
mpeg audio frames . |
void |
displayErrors(java.io.PrintStream printStream)
displays any errors found in the ID3v2.x tag from the .mp3 file.
|
java.util.List<java.lang.String> |
getErrors()
gets a list of any errors found in the ID3v2.x tag.
|
long |
getFileSize()
returns the size (in bytes) of the .mp3 file.
|
ID3v24Tag |
getID3v24TagAtEnd()
gets the optional
ID3v2.4 tag found at the end of an .mp3 file. |
java.lang.String |
getPath()
gets the path to the .mp3 file.
|
protected java.lang.String |
getReadOnlyErrorMessage()
gets the read only error message to display to users when they try to modify an .mp3 file loaded from a URL.
|
boolean |
hasErrors()
determines if the mp3 file had any errors in the information stored in the frames of the ID3v2.x tag.
|
boolean |
hasID3v1Tag()
determines whether the .mp3 file has an
ID3v1 tag at the end of the .mp3 file. |
boolean |
hasID3v24TagAtEnd()
determines whether the .mp3 file has an
ID3v2.4 tag at the end of the .mp3 file. |
boolean |
isConstantBitRate()
determines whether the mp3 file is encoded at a constant bit rate (
CBR ). |
protected void |
readFirstMPEGFrame(java.io.InputStream inputStream)
reads in the first mpeg audio frame from the .mp3 file.
|
protected boolean |
readID3Tag(java.io.InputStream inputStream)
reads in the ID3v2.x tag from the .mp3 file.
|
void |
removeID3v1Tag()
remove the
ID3v1 tag at the end of the .mp3 file. |
void |
removeID3v24TagAtEnd()
remove the
ID3v2.4 tag at the end of the .mp3 file. |
protected void |
saveID3v23()
save the
ID3v2.3 tag to the .mp3 file. |
protected void |
saveID3v24()
save the
ID3v2.4 tag to the .mp3 file. |
java.lang.String |
toString()
gets a string representation of the mp3 file.
|
java.util.List<java.lang.String> |
validateMPEGFrames()
This method reads through the audio portion of an .mp3 file and validates the
MPEG audio frames . |
addV24Frame, getID3v24Tag, getV24Album, getV24AttachedPicture, getV24AttachedPictureFrame, getV24AttachedPictures, getV24AudioDuration, getV24AudioSize, getV24Band, getV24Comments, getV24CommentsFrame, getV24Errors, getV24Frame, getV24Frames, getV24LeadPerformer, getV24LyricsBy, getV24MusicBy, getV24MusicType, getV24Publisher, getV24Rating, getV24SynchronizedLyrics, getV24SynchronizedLyricsFrame, getV24Text, getV24TextAsInteger, getV24Title, getV24Track, getV24UnsynchronizedLyrics, getV24UnsynchronizedLyricsFrame, getV24Year, hasV24Errors, removeV24Album, removeV24AttachedPicture, removeV24AttachedPictures, removeV24AudioDuration, removeV24AudioSize, removeV24Band, removeV24Comments, removeV24Comments, removeV24Frame, removeV24Frames, removeV24LeadPerformer, removeV24LyricsBy, removeV24MusicBy, removeV24MusicType, removeV24Publisher, removeV24Rating, removeV24SynchronizedLyrics, removeV24Title, removeV24Track, removeV24UnsynchronizedLyrics, removeV24Year, setV24Album, setV24AttachedPicture, setV24AudioDuration, setV24AudioSize, setV24Band, setV24Comments, setV24LeadPerformer, setV24LyricsBy, setV24MusicBy, setV24MusicType, setV24MusicType, setV24Publisher, setV24Rating, setV24SynchronizedLyrics, setV24SynchronizedLyrics, setV24SynchronizedLyrics, setV24Text, setV24Text, setV24Text, setV24Title, setV24Track, setV24UnsynchronizedLyrics, setV24Year
addV23Frame, getID3v23Tag, getV23Album, getV23AttachedPicture, getV23AttachedPictureFrame, getV23AttachedPictures, getV23AudioDuration, getV23AudioSize, getV23Band, getV23Comments, getV23CommentsFrame, getV23Errors, getV23Frame, getV23Frames, getV23LeadPerformer, getV23LyricsBy, getV23MusicBy, getV23MusicType, getV23Publisher, getV23Rating, getV23SynchronizedLyrics, getV23SynchronizedLyricsFrame, getV23Text, getV23TextAsInteger, getV23Title, getV23Track, getV23UnsynchronizedLyrics, getV23UnsynchronizedLyricsFrame, getV23Year, hasV23Errors, removeV23Album, removeV23AttachedPicture, removeV23AttachedPictures, removeV23AudioDuration, removeV23AudioSize, removeV23Band, removeV23Comments, removeV23Comments, removeV23Frame, removeV23Frames, removeV23LeadPerformer, removeV23LyricsBy, removeV23MusicBy, removeV23MusicType, removeV23Publisher, removeV23Rating, removeV23SynchronizedLyrics, removeV23Title, removeV23Track, removeV23UnsynchronizedLyrics, removeV23Year, setV23Album, setV23AttachedPicture, setV23AudioDuration, setV23AudioSize, setV23Band, setV23Comments, setV23LeadPerformer, setV23LyricsBy, setV23MusicBy, setV23MusicType, setV23MusicType, setV23Publisher, setV23Rating, setV23SynchronizedLyrics, setV23SynchronizedLyrics, setV23SynchronizedLyrics, setV23Text, setV23Text, setV23Text, setV23Title, setV23Track, setV23UnsynchronizedLyrics, setV23Year
protected java.io.File mp3File
protected java.net.URL mp3Url
protected long fileSize
protected long tagSize
protected long audioSize
protected MPEGFrame mpegFrame
protected int bitrate
protected BitrateType bitrateType
public MP3Base(java.lang.String mp3File) throws java.io.IOException
mp3File
- path to the .mp3 file from which to get information.java.io.IOException
- if there is a problem reading the .mp3 file.public MP3Base(java.io.File mp3File) throws java.io.IOException
mp3File
- .mp3 file from which to get information.java.io.IOException
- if there is a problem reading the .mp3 file.public MP3Base(java.net.URL mp3Url) throws java.io.IOException
mp3Url
- URL of an .mp3 file from which to get information.java.io.IOException
- if there is a problem reading the .mp3 file.protected boolean readID3Tag(java.io.InputStream inputStream) throws java.io.IOException
inputStream
- input stream pointing to the beginning of an .mp3 filejava.io.IOException
- if there is a problem reading the .mp3 file.protected void readFirstMPEGFrame(java.io.InputStream inputStream) throws java.io.IOException
frame header
, side information
,
followed by some optional VBR
headers, and then by the audio data
.
This method searches the audio section of the .mp3 file until it finds the first valid mpeg audio frame header.inputStream
- input stream pointing to the beginning of the audio portion of an .mp3 file.java.io.IOException
- if there is a problem reading the MPEG audio section of the .mp3 file.public java.util.List<java.lang.String> validateMPEGFrames() throws java.io.IOException
MPEG audio frames
. It makes sure that the MPEG audio frames:MPEG frame headers
frame header
followed by side information
followed by
audio data
)constant bit rate
Xing
, Lame
, and VBRI
headers occur only in the 1st
MPEG audio frame
VBR
encoded .mp3 files contain a VBR headerjava.io.IOException
- if the .mp3 file can not be read.public boolean hasErrors()
getErrors()
,
displayErrors(PrintStream)
public java.util.List<java.lang.String> getErrors()
hasErrors()
,
displayErrors(PrintStream)
public void displayErrors(java.io.PrintStream printStream)
printStream
- print stream used to write out the errors.getErrors()
,
hasErrors()
protected java.lang.String getReadOnlyErrorMessage()
public java.lang.String getPath()
// load the song "Take Hold of the Flame" from Queensryche's album, "The Warning".
MP3 mp3 = new MP3("c:/mp3/queensryche/the warning/take hold of the flame.mp3");
System.out.println("the mp3 file was loaded from " + mp3.getPath());
// load the song "Take Hold of the Flame" from Queensryche's album, "The Warning".
MP3 mp3 = new MP3("http://www.beaglebuddy.com/mp3/queensryche/the warning/take hold of the flame.mp3");
System.out.println("the mp3 file was loaded from " + mp3.getPath());
public long getFileSize()
protected int calculateAudioDuration()
mpeg audio frames
.public boolean isConstantBitRate()
CBR
).CBR
).public boolean hasID3v1Tag() throws java.io.IOException, java.lang.IllegalStateException
ID3v1 tag
at the end of the .mp3 file. This method can only be called on mp3's loaded from a file.ID3v1 tag
at the end of the .mp3 file.java.io.IOException
- if there is a problem reading the .mp3 file.java.lang.IllegalStateException
- if the mp3 song was loaded from a URL and therefore will take a considerable amount of time to reach the ID3v1 tag
at the end of the .mp3 file.public ID3v24Tag getID3v24TagAtEnd() throws java.io.IOException, java.lang.IllegalStateException
ID3v2.4 tag
found at the end of an .mp3 file. This really is a stupid addition to the Id3v2.4 standard.ID3v2.4 tag
found at the end of an .mp3 file if present. Otherwise null is returned.java.io.IOException
- if there is a problem reading the .mp3 file.java.lang.IllegalStateException
- if the mp3 song was loaded from a URL and therefore will take a considerable amount of time to reach the ID3v2.4 tag
at the end of the .mp3 file.public boolean hasID3v24TagAtEnd() throws java.io.IOException, java.lang.IllegalStateException
ID3v2.4 tag
at the end of the .mp3 file.ID3v2.4 tag
at the end of the .mp3 file.java.io.IOException
- if there is a problem reading the .mp3 file.java.lang.IllegalStateException
- if the mp3 song was loaded from a URL and therefore will take a considerable amount of time to reach the ID3v2.4 tag
at the end of the .mp3 file.public void removeID3v1Tag() throws java.io.IOException
java.io.IOException
- if there was an error truncating ID3v1 tag
from the end of the .mp3 file.java.lang.IllegalStateException
- if the mp3 song was loaded from a URL and is therefore considered to be read only and thus may not be modified.public void removeID3v24TagAtEnd() throws java.io.IOException
java.io.IOException
- if there was an error truncating ID3v2.4 tag
from the end of the .mp3 file.java.lang.IllegalStateException
- if the mp3 song was loaded from a URL and is therefore considered to be read only and thus may not be modified.protected void saveID3v23() throws java.io.IOException
ID3v2.3 tag
to the .mp3 file.
This is a very messy method, and you really have to understand the ID3v2.3 structure to understand this method.
So, if you can, by all means, avoid reading the code in this method.
java.io.IOException
- if there was an error writing the ID3v2.3 tag
to the .mp3 file.protected void saveID3v24() throws java.io.IOException
ID3v2.4 tag
to the .mp3 file.
This is a very messy method, and you really have to understand the ID3v2.4 structure to understand this method.
So, if you can, by all means, avoid reading the code in this method.
java.io.IOException
- if there was an error writing the ID3v2.4 tag
to the .mp3 file.public java.lang.String toString()
toString
in class java.lang.Object