📄 flactag.java
字号:
package com.hadeslee.audiotag.tag.flac;
import com.hadeslee.audiotag.tag.vorbiscomment.VorbisCommentTag;
import com.hadeslee.audiotag.tag.id3.valuepair.ImageFormats;
import com.hadeslee.audiotag.tag.id3.valuepair.TextEncoding;
import com.hadeslee.audiotag.tag.id3.valuepair.PictureTypes;
import com.hadeslee.audiotag.audio.flac.metadatablock.MetadataBlockDataPicture;
import com.hadeslee.audiotag.audio.generic.Utils;
import com.hadeslee.audiotag.tag.FieldDataInvalidException;
import com.hadeslee.audiotag.tag.KeyNotFoundException;
import com.hadeslee.audiotag.tag.Tag;
import com.hadeslee.audiotag.tag.TagField;
import com.hadeslee.audiotag.tag.TagFieldKey;
import javax.imageio.ImageIO;
import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.awt.image.BufferedImage;
import java.io.ByteArrayOutputStream;
import java.io.DataOutputStream;
import java.io.IOException;
/**
* Flac uses Vorbis Comment for most of its metadata and a Flac Picture Block for images
*
* <p>
* This class enscapulates the items into a single tag
*/
public class FlacTag implements Tag
{
VorbisCommentTag tag = null;
List<MetadataBlockDataPicture> images = new ArrayList<MetadataBlockDataPicture>();
public FlacTag(VorbisCommentTag tag,List<MetadataBlockDataPicture> images)
{
this.tag = tag;
this.images = images;
}
/**
*
* @return images
*/
public List<MetadataBlockDataPicture> getImages()
{
return images;
}
/**
*
* @return the vorbis tag (this is what handles text metadata)
*/
public VorbisCommentTag getVorbisCommentTag()
{
return tag;
}
/**
* Adds a tagfield to the structure.<br>
*
* <p>It is not recommended to use this method for normal use of the
* audiolibrary. The developer will circumvent the underlying
* implementation. For example, if one adds a field with the field id
* "TALB" for an mp3 file, and the given {@link com.hadeslee.jaudiotagger.tag.TagField}
* implementation does not return a text field compliant data with
* {@link com.hadeslee.jaudiotagger.tag.TagField#getRawContent()} other software and the audio library
* won't read the file correctly, if they do read it at all. <br>
* So for short:<br>
* <uil>
* <li>The field is stored without validation</li>
* <li>No conversion of data is perfomed</li>
* </ul>
*
* @param field
* The field to add.
*/
public void add(TagField field) throws FieldDataInvalidException
{
if(field instanceof MetadataBlockDataPicture)
{
images.add((MetadataBlockDataPicture)field);
}
else
{
tag.add(field);
}
}
/**
* Adds an album to the tag.<br>
*
* @param album
* Album description
*/
public void addAlbum(String album) throws FieldDataInvalidException
{
tag.addAlbum(album);
}
/**
* Adds an artist to the tag.<br>
*
* @param artist
* Artist's name
*/
public void addArtist(String artist) throws FieldDataInvalidException
{
tag.addArtist(artist);
}
/**
* Adds a comment to the tag.<br>
*
* @param comment
* Comment.
*/
public void addComment(String comment) throws FieldDataInvalidException
{
tag.addComment(comment);
}
/**
* Adds a genre to the tag.<br>
*
* @param genre
* Genre
*/
public void addGenre(String genre) throws FieldDataInvalidException
{
tag.addGenre(genre);
}
/**
* Adds a title to the tag.<br>
*
* @param title
* Title
*/
public void addTitle(String title) throws FieldDataInvalidException
{
tag.addTitle(title);
}
/**
* Adds a track to the tag.<br>
*
* @param track
* Track
*/
public void addTrack(String track) throws FieldDataInvalidException
{
tag.addTrack(track);
}
/**
* Adds a year to the Tag.<br>
*
* @param year
* Year
*/
public void addYear(String year) throws FieldDataInvalidException
{
tag.addYear(year);
}
/**
* Returns a {@linkplain List list} of {@link TagField} objects whose "{@linkplain TagField#getId() id}"
* is the specified one.<br>
*
* @param id
* The field id.
* @return A list of {@link TagField} objects with the given "id".
*/
public List<TagField> get(String id)
{
if(id.equals(TagFieldKey.COVER_ART.name()))
{
List <TagField> castImages = new ArrayList<TagField>();
for(MetadataBlockDataPicture image:images)
{
castImages.add(image);
}
return castImages;
}
else
{
return tag.get(id);
}
}
/**
*
* @return
*/
public List<TagField> getAlbum()
{
return tag.getAlbum();
}
/**
*
* @return
*/
public List<TagField> getArtist()
{
return tag.getArtist();
}
/**
*
* @return
*/
public List<TagField> getComment()
{
return tag.getComment();
}
/**
*
* @return
*/
public List<TagField> getGenre()
{
return tag.getGenre();
}
/**
*
* @return
*/
public List<TagField> getTitle()
{
return tag.getTitle();
}
/**
*
* @return
*/
public List<TagField> getTrack()
{
return tag.getTrack();
}
/**
*
* @return
*/
public List<TagField> getYear()
{
return tag.getYear();
}
/**
*
* @return
*/
public String getFirstAlbum()
{
return tag.getFirstAlbum();
}
/**
*
* @return
*/
public String getFirstArtist()
{
return tag.getFirstArtist();
}
/**
*
* @return
*/
public String getFirstComment()
{
return tag.getFirstComment();
}
/**
*
* @return
*/
public String getFirstGenre()
{
return tag.getFirstGenre();
}
/**
*
* @return
*/
public String getFirstTitle()
{
return tag.getFirstTitle();
}
/**
*
* @return
*/
public String getFirstTrack()
{
return tag.getFirstTrack();
}
/**
*
* @return
*/
public String getFirstYear()
{
return tag.getFirstYear();
}
/**
* Returns <code>true</code>, if at least one of the contained
* {@linkplain TagField fields} is a common field ({@link TagField#isCommon()}).
*
* @return <code>true</code> if a {@linkplain TagField#isCommon() common}
* field is present.
*/
public boolean hasCommonFields()
{
return tag.hasCommonFields();
}
/**
* Determines whether the tag has at least one field with the specified
* "id".
*
* @param id
* The field id to look for.
* @return <code>true</code> if tag contains a {@link TagField} with the
* given {@linkplain TagField#getId() id}.
*/
public boolean hasField(String id)
{
if(id.equals(TagFieldKey.COVER_ART.name()))
{
return images.size()>0;
}
else
{
return tag.hasField(id);
}
}
/**
* Determines whether the tag has no fields specified.<br>
*
* <p>If there are no images we return empty if either there is no VorbisTag or if there is a
* VorbisTag but it is empty
*
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -