📄 mp3file.java
字号:
/** * Set the track number of this mp3. * * @param track the track number of this mp3 */ public void setTrack( int track ) { if( allow( ID3V1 ) ) { id3v1.setTrack( track ); } if( allow( ID3V2 ) ) { id3v2.setTextFrame( ID3v2Frames.TRACK_NUMBER, String.valueOf(track) ); } } /** * Set the composer of this mp3 (id3v2 only). * * @param composer the composer of this mp3 */ public void setComposer( String composer ) { if( allow( ID3V2 ) ) { id3v2.setTextFrame( ID3v2Frames.COMPOSER, composer ); } } /** * Set the original artist of this mp3 (id3v2 only). * * @param artist the original artist of this mp3 */ public void setOriginalArtist( String artist ) { if( allow( ID3V2 ) ) { id3v2.setTextFrame( ID3v2Frames.ORIGINAL_ARTIST, artist ); } } /** * Add some copyright information to this mp3 (id3v2 only). * * @param copyright copyright information related to this mp3 */ public void setCopyrightInfo( String copyright ) { if( allow( ID3V2 ) ) { id3v2.setTextFrame( ID3v2Frames.COPYRIGHT_MESSAGE, copyright ); } } /** * Add a link to this mp3 (id3v2 only). This includes a description of * the url and the url itself. * * @param desc a description of the url * @param url the url itself */ public void setUserDefinedURL( String desc, String url ) { if( allow( ID3V2 ) ) { id3v2.setUserDefinedURLFrame( desc, url ); } } /** * Add a field of miscellaneous text (id3v2 only). This includes a * description of the text and the text itself. * * @param desc a description of the text * @param text the text itself */ public void setUserDefinedText( String desc, String text ) { if( allow( ID3V2 ) ) { id3v2.setUserDefinedTextFrame( desc, text ); } } /** * Set who encoded the mp3 (id3v2 only). * * @param encBy who encoded the mp3 */ public void setEncodedBy( String encBy ) { if( allow( ID3V2 ) ) { id3v2.setTextFrame( ID3v2Frames.ENCODED_BY, encBy ); } } /** * Set the text of the text frame specified by the id (id3v2 only). The * id should be one of the static strings specifed in ID3v2Frames class. * All id's that begin with 'T' (excluding "TXXX") are considered text * frames. * * @param id the id of the frame to set the data for * @param data the data to set */ public void setTextFrame( String id, String data ) { if( allow( ID3V2 ) ) { id3v2.setTextFrame( id, data ); } } /** * Set the data of the frame specified by the id (id3v2 only). The id * should be one of the static strings specified in ID3v2Frames class. * * @param id the id of the frame to set the data for * @param data the data to set */ public void setFrameData( String id, byte[] data ) { if( allow( ID3V2 ) ) { id3v2.updateFrameData( id, data ); } } /** * Returns the artist of the mp3 if set and the empty string if not. * * @return the artist of the mp3 * @exception ID3v2FormatException if the data of the field is incorrect */ public String getArtist() throws ID3v2FormatException { String str = new String(); if( allow( ID3V2 ) ) { str = id3v2.getFrameDataString( ID3v2Frames.LEAD_PERFORMERS ); } else if( allow( ID3V1) ) { str = id3v1.getArtist(); } return str; } /** * Returns the album of the mp3 if set and the empty string if not. * * @return the album of the mp3 * @exception ID3v2FormatException if the data of the field is incorrect */ public String getAlbum() throws ID3v2FormatException { String str = new String(); if( allow( ID3V2 ) ) { str = id3v2.getFrameDataString( ID3v2Frames.ALBUM ); } else if( allow( ID3V1) ) { str = id3v1.getAlbum(); } return str; } /** * Returns the comment field of this mp3 if set and the empty string if * not. * * @return the comment field of this mp3 * @exception ID3v2FormatException if the data of the field is incorrect */ public String getComment() throws ID3v2FormatException { String str = new String(); if( allow( ID3V2 ) ) { str = id3v2.getFrameDataString( ID3v2Frames.COMMENTS ); } else if( allow( ID3V1) ) { str = id3v1.getComment(); } return str; } /** * Returns the genre of this mp3 if set and the empty string if not. * * @return the genre of this mp3 * @exception ID3v2FormatException if the data of this field is incorrect */ public String getGenre() throws ID3v2FormatException { String str = new String(); if( allow( ID3V2 ) ) { str = id3v2.getFrameDataString( ID3v2Frames.CONTENT_TYPE ); } else if( allow( ID3V1) ) { str = id3v1.getGenreString(); } return str; } /** * Returns the title of this mp3 if set and the empty string if not. * * @return the title of this mp3 * @exception ID3v2FormatException if the data of this field is incorrect */ public String getTitle() throws ID3v2FormatException { String str = new String(); if( allow( ID3V2 ) ) { str = id3v2.getFrameDataString( ID3v2Frames.TITLE ); } else if( allow( ID3V1) ) { str = id3v1.getTitle(); } return str; } /** * Returns the track of this mp3 if set and the empty string if not. * * @return the track of this mp3 * @exception ID3v2FormatException if the data of this field is incorrect */ public String getTrack() throws ID3v2FormatException { String str = new String(); if( allow( ID3V2 ) ) { str = id3v2.getFrameDataString( ID3v2Frames.TRACK_NUMBER ); } else if( allow( ID3V1) ) { str = String.valueOf( id3v1.getTrack() ); } return str; } /** * Returns the year of this mp3 if set and the empty string if not. * * @return the year of this mp3 * @exception ID3v2FormatException if the data of this field is incorrect */ public String getYear() throws ID3v2FormatException { String str = new String(); if( allow( ID3V2 ) ) { str = id3v2.getFrameDataString( ID3v2Frames.YEAR); } else if( allow( ID3V1) ) { str = id3v1.getYear(); } return str; } /** * Returns the composer of this mp3 if set and the empty string if not * (id3v2 only). * * @return the composer of this mp3 * @exception ID3v2FormatException if the data of this field is incorrect */ public String getComposer() throws ID3v2FormatException { String str = new String(); if( allow( ID3V2 ) ) { str = id3v2.getFrameDataString( ID3v2Frames.COMPOSER ); } return str; } /** * Returns the original artist of this mp3 if set and the empty string * if not (id3v2 only). * * @return the original artist of this mp3 * @exception ID3v2FormatException if the data of this field is incorrect */ public String getOriginalArtist() throws ID3v2FormatException { String str = new String(); if( allow( ID3V2 ) ) { str = id3v2.getFrameDataString( ID3v2Frames.ORIGINAL_ARTIST ); } return str; } /** * Returns the copyright info of this mp3 if set and the empty string * if not (id3v2 only). * * @return the copyright info of this mp3 * @exception ID3v2FormatException if the data of this field is incorrect */ public String getCopyrightInfo() throws ID3v2FormatException { String str = new String(); if( allow( ID3V2 ) ) { str = id3v2.getFrameDataString( ID3v2Frames.COPYRIGHT_MESSAGE ); } return str; } /** * Returns the user defined url of this mp3 if set and the empty string * if not (id3v2 only). * * @return the user defined url of this mp3 * @exception ID3v2FormatException if the data of this field is incorrect */ public String getUserDefinedURL() throws ID3v2FormatException { String str = new String(); if( allow( ID3V2 ) ) { str = id3v2.getFrameDataString( ID3v2Frames.USER_DEFINED_URL ); } return str; } /** * Returns who encoded this mp3 if set and the empty string if not * (id3v2 only). * * @return who encoded this mp3 * @exception ID3v2FormatException if the data of this field is incorrect */ public String getEncodedBy() throws ID3v2FormatException { String str = new String(); if( allow( ID3V2 ) ) { str = id3v2.getFrameDataString( ID3v2Frames.ENCODED_BY ); } return str; } /** * Returns the textual information contained in the frame specifed by the * id. If the frame does not contain any textual information or does not * exist, then the empty string is returned (id3v2 only). The id should * be one of the static strings defined in the ID3v2Frames class. * * @param id the id of the frame to get data from * @return the textual information of the frame * @exception ID3v2FormatException if the data of the frame is incorrect */ public String getFrameDataString( String id ) throws ID3v2FormatException { String str = new String(); if( allow( ID3V2 ) ) { str = id3v2.getFrameDataString( id ); } return str; } /** * Returns the data contained in the frame specified by the id (id3v2 only) * . If the frame does not exist, a zero length array will be returned. * The id should be one of the static strings defined in the ID3v2Frames * class. * * @param id the id of the frame to get data from * @return the data contained in the frame */ public byte[] getFrameDataBytes( String id ) { byte[] b = new byte[0]; if( allow( ID3V2 ) ) { b = id3v2.getFrameData( id ); } return b; } /** * Returns the currently set tagging type. * * @return the current tagging type */ public int getTaggingType() { return tagType; } /** * Set the tagging type. This determines what type of id3 tags are * read/written. This should be one of the constants defined by this * class: BOTH_TAGS, ID3V1_ONLY, ID3V2_ONLY, EXISTING_TAGS_ONLY, NO_TAGS * * @param newType the new tagging type */ public void setTaggingType( int newType ) { tagType = newType; } /** * Checks whether it is ok to read or write from the tag version specified * based on the tagType passed to the constructor. The tagVersion * parameter should be either ID3V1 or ID3V2. * * @param tagVersion the id3 version to check * @return true if it is ok to proceed with the read/write */ private boolean allow( int tagVersion ) { return this.allow( tagVersion, tagType ); } /** * Checks whether it is ok to read or write from the tag version specified * based on the tagType passed to the method. The tagVersion parameter * should be either ID3V1 or ID3V2. The type parameter should be either * BOTH_TAGS, ID3V1_ONLY, ID3V2_ONLY, NO_TAGS, or EXISTING_TAGS_ONLY. * * @param tagVersion the id3 version to check * @param type specifies what conditions the tags are allowed to proceed * @return true if it is ok to proceed with the read/write */ private boolean allow( int tagVersion, int type ) { boolean retval = false; if( tagVersion == ID3V1 ) { retval = ((type == EXISTING_TAGS_ONLY) && id3v1.tagExists()) || (type == ID3V1_ONLY) || (type == BOTH_TAGS); } else if( tagVersion == ID3V2 ) { retval = ((type == EXISTING_TAGS_ONLY) && id3v2.tagExists()) || (type == ID3V2_ONLY) || (type == BOTH_TAGS); } return retval; } /** * Return a string representation of this object. This includes all the * information contained within the mpeg header and id3 tags as well as * certain file attributes. * * @return a string representation of this object */ public String toString() { return "MP3File" + "\nPath:\t\t\t\t" + mp3.getAbsolutePath() + "\nFileSize:\t\t\t" + mp3.length() + " bytes\nPlayingTime:\t\t\t" + getPlayingTimeString() + "\n" + head + "\n" + id3v1 + "\n" + id3v2; } /** * Returns true if the object o is equal to this MP3File. * * @param o the object to compare * @return true if the object o is equal to this MP3File */ public boolean equals( Object o ) { return mp3.equals( o ); } /** * Compare this MP3File to the specified object. The comparison * implementation comes from the MP3Comparator class, look there for * details on the comparison method. * * @param o the object to compare to this one * @return a positive number if this object is greater than the other, * 0 if the object are equal, or a negative number if this object * is less than the other */ public int compareTo( Object o ) { return comparator.compare( this, o ); }} // MP3File
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -