本文整理汇总了Java中org.jaudiotagger.tag.id3.AbstractID3v2Tag类的典型用法代码示例。如果您正苦于以下问题:Java AbstractID3v2Tag类的具体用法?Java AbstractID3v2Tag怎么用?Java AbstractID3v2Tag使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
AbstractID3v2Tag类属于org.jaudiotagger.tag.id3包,在下文中一共展示了AbstractID3v2Tag类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getTagAndConvertOrCreateAndSetDefault
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
/**
* Get the tag and convert to the default tag version or if the file doesn't have one at all, create a default tag
* set as tag for this file
*
* Conversions are currently only necessary/available for formats that support ID3
*
* @return
*/
public Tag getTagAndConvertOrCreateAndSetDefault()
{
Tag tag = getTagOrCreateDefault();
/* TODO Currently only works for Dsf We need additional check here for Wav and Aif because they wrap the ID3 tag so never return
* null for getTag() and the wrapper stores the location of the existing tag, would that be broken if tag set to something else
*/
if(tag instanceof AbstractID3v2Tag)
{
Tag convertedTag = convertID3Tag((AbstractID3v2Tag)tag, TagOptionSingleton.getInstance().getID3V2Version());
if(convertedTag!=null)
{
setTag(convertedTag);
}
else
{
setTag(tag);
}
}
else
{
setTag(tag);
}
return getTag();
}
示例2: getMP3StartByte
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
/**
* Used by tags when writing to calculate the location of the music file
*
* @param file
* @return the location within the file that the audio starts
* @throws java.io.IOException
* @throws org.jaudiotagger.audio.exceptions.InvalidAudioFrameException
*/
public long getMP3StartByte(File file) throws InvalidAudioFrameException, IOException {
try {
//Read ID3v2 tag size (if tag exists) to allow audio header parsing to skip over tag
long startByte = AbstractID3v2Tag.getV2TagSizeIfExists(file);
MP3AudioHeader audioHeader = new MP3AudioHeader(file, startByte);
if (startByte != audioHeader.getMp3StartByte()) {
logger.config("First header found after tag:" + audioHeader);
audioHeader = checkAudioStart(startByte, audioHeader);
}
return audioHeader.getMp3StartByte();
} catch (InvalidAudioFrameException iafe) {
throw iafe;
} catch (IOException ioe) {
throw ioe;
}
}
示例3: readTag
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
private Tag readTag(RandomAccessFile file, long tagOffset) throws CannotReadException, IOException {
//Move to start of ID3Tag and read rest of file into ByteBuffer
file.seek(tagOffset);
ByteBuffer tagBuffer = Utils.readFileDataIntoBufferLE(file, (int) (file.length() - file.getFilePointer()));
//Work out ID3 major version
int majorVersion = tagBuffer.get(AbstractID3v2Tag.FIELD_TAG_MAJOR_VERSION_POS);
try {
logger.log(Level.FINE, "Start creating ID3v2 Tag for version: " + majorVersion);
switch (majorVersion) {
case ID3v22Tag.MAJOR_VERSION:
return new ID3v22Tag(tagBuffer, "");
case ID3v23Tag.MAJOR_VERSION:
return new ID3v23Tag(tagBuffer, "");
case ID3v24Tag.MAJOR_VERSION:
return new ID3v24Tag(tagBuffer, "");
default:
logger.log(Level.WARNING, "Unknown major ID3v2 version " + majorVersion + ". Returning an empty ID3v2 Tag.");
return new ID3v24Tag();
}
} catch (TagException e) {
throw new CannotReadException("Could not create ID3v2 Tag");
}
}
示例4: getMP3StartByte
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
@SuppressWarnings("TryWithIdenticalCatches")
public long getMP3StartByte(File file) throws InvalidAudioFrameException, IOException {
//noinspection CaughtExceptionImmediatelyRethrown,CaughtExceptionImmediatelyRethrown
try {
//Read ID3v2 tag size (if tag exists) to allow audio header parsing to skip over tag
long startByte = AbstractID3v2Tag.getV2TagSizeIfExists(file);
MP3AudioHeader audioHeader = new MP3AudioHeader(file, startByte);
if (startByte != audioHeader.getMp3StartByte()) {
logger.config("First header found after tag:" + audioHeader);
audioHeader = checkAudioStart(startByte, audioHeader);
}
return audioHeader.getMp3StartByte();
} catch (InvalidAudioFrameException iafe) {
throw iafe;
} catch (IOException ioe) {
throw ioe;
}
}
示例5: isId3v2Tag
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
/**
* Reads 3 bytes to determine if the tag really looks like ID3 data.
*/
private boolean isId3v2Tag(final ByteBuffer headerData) throws IOException
{
for (int i = 0; i < AbstractID3v2Tag.FIELD_TAGID_LENGTH; i++)
{
if (headerData.get() != AbstractID3v2Tag.TAG_ID[i])
{
return false;
}
}
return true;
}
示例6: read
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
/**
* Read next PageHeader from file
* @param raf
* @return
* @throws IOException
* @throws CannotReadException
*/
public static OggPageHeader read(RandomAccessFile raf) throws IOException, CannotReadException
{
long start = raf.getFilePointer();
logger.fine("Trying to read OggPage at:" + start);
byte[] b = new byte[OggPageHeader.CAPTURE_PATTERN.length];
raf.read(b);
if (!(Arrays.equals(b, OggPageHeader.CAPTURE_PATTERN)))
{
raf.seek(start);
if(AbstractID3v2Tag.isId3Tag(raf))
{
logger.warning(ErrorMessage.OGG_CONTAINS_ID3TAG.getMsg(raf.getFilePointer() - start));
raf.read(b);
if ((Arrays.equals(b, OggPageHeader.CAPTURE_PATTERN)))
{
//Go to the end of the ID3 header
start=raf.getFilePointer() - OggPageHeader.CAPTURE_PATTERN.length;
}
}
else
{
throw new CannotReadException(ErrorMessage.OGG_HEADER_CANNOT_BE_FOUND.getMsg(new String(b)));
}
}
raf.seek(start + OggPageHeader.FIELD_PAGE_SEGMENTS_POS);
int pageSegments = raf.readByte() & 0xFF; //unsigned
raf.seek(start);
b = new byte[OggPageHeader.OGG_PAGE_HEADER_FIXED_LENGTH + pageSegments];
raf.read(b);
OggPageHeader pageHeader = new OggPageHeader(b);
pageHeader.setStartByte(start);
//Now just after PageHeader, ready for Packet Data
return pageHeader;
}
示例7: readTag
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
/**
* Reads the ID3v2 tag starting at the {@code tagOffset} position in the
* supplied file.
*
* @param fc the filechannel from which to read
* @param dsd the dsd chunk
* @param fileName
* @return the read tag or an empty tag if something went wrong. Never
* <code>null</code>.
* @throws IOException if cannot read file.
*/
private Tag readTag(FileChannel fc, DsdChunk dsd, String fileName) throws CannotReadException, IOException {
if (dsd.getMetadataOffset() > 0) {
fc.position(dsd.getMetadataOffset());
ID3Chunk id3Chunk = ID3Chunk.readChunk(Utils.readFileDataIntoBufferLE(fc, (int) (fc.size() - fc.position())));
if (id3Chunk != null) {
int version = id3Chunk.getDataBuffer().get(AbstractID3v2Tag.FIELD_TAG_MAJOR_VERSION_POS);
try {
switch (version) {
case ID3v22Tag.MAJOR_VERSION:
return new ID3v22Tag(id3Chunk.getDataBuffer(), "");
case ID3v23Tag.MAJOR_VERSION:
return new ID3v23Tag(id3Chunk.getDataBuffer(), "");
case ID3v24Tag.MAJOR_VERSION:
return new ID3v24Tag(id3Chunk.getDataBuffer(), "");
default:
logger.log(Level.WARNING, fileName + " Unknown ID3v2 version " + version + ". Returning an empty ID3v2 Tag.");
return null;
}
} catch (TagException e) {
throw new CannotReadException(fileName + " Could not read ID3v2 tag:corruption");
}
} else {
logger.log(Level.WARNING, fileName + " No existing ID3 tag(1)");
return null;
}
} else {
logger.log(Level.WARNING, fileName + " No existing ID3 tag(2)");
return null;
}
}
示例8: setID3v2Tag
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
/**
* Sets the v2 tag to the v2 tag provided as an argument.
* Also store a v24 version of tag as v24 is the interface to be used
* when talking with client applications.
*
* @param id3v2tag
*/
public void setID3v2Tag(AbstractID3v2Tag id3v2tag) {
this.id3v2tag = id3v2tag;
if (id3v2tag instanceof ID3v24Tag) {
this.id3v2Asv24tag = (ID3v24Tag) this.id3v2tag;
} else {
this.id3v2Asv24tag = new ID3v24Tag(id3v2tag);
}
}
示例9: delete
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
/**
* Remove tag from file
*
* @param mp3tag
* @throws FileNotFoundException
* @throws IOException
*/
public void delete(AbstractTag mp3tag) throws FileNotFoundException, IOException {
RandomAccessFile raf = new RandomAccessFile(this.file, "rw");
mp3tag.delete(raf);
raf.close();
if (mp3tag instanceof ID3v1Tag) {
id3v1tag = null;
}
if (mp3tag instanceof AbstractID3v2Tag) {
id3v2tag = null;
}
}
示例10: setTag
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
/**
* Set the Tag
* <p>
* If the parameter tag is a v1tag then the v1 tag is set if v2tag then the v2tag.
*
* @param tag
*/
public void setTag(Tag tag) {
this.tag = tag;
if (tag instanceof ID3v1Tag) {
setID3v1Tag((ID3v1Tag) tag);
} else {
setID3v2Tag((AbstractID3v2Tag) tag);
}
}
示例11: getTagAndConvertOrCreateAndSetDefault
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
/**
* Get the ID3v2 tag and convert to preferred version or if the file doesn't have one at all
* create a default tag of preferred version and set it. The file may already contain a ID3v1 tag but because
* this is not terribly useful the v1tag is not considered for this problem.
*
* @return
*/
@Override
public Tag getTagAndConvertOrCreateAndSetDefault() {
Tag tag = getTagOrCreateDefault();
Tag convertedTag = convertID3Tag((AbstractID3v2Tag) tag, TagOptionSingleton.getInstance().getID3V2Version());
if (convertedTag != null) {
setTag(convertedTag);
} else {
setTag(tag);
}
return getTag();
}
示例12: isId3v2Tag
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
private boolean isId3v2Tag() throws IOException
{
fc.position(0);
if(AbstractID3v2Tag.isId3Tag(fc))
{
logger.warning(loggingName + ErrorMessage.FLAC_CONTAINS_ID3TAG.getMsg(fc.position()));
//FLAC Stream immediately after end of id3 tag
if (isFlacHeader())
{
return true;
}
}
return false;
}
示例13: read
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
/**
* Read next PageHeader from file
*
* @param raf
* @return
* @throws IOException
* @throws CannotReadException
*/
public static OggPageHeader read(RandomAccessFile raf) throws IOException, CannotReadException {
long start = raf.getFilePointer();
logger.fine("Trying to read OggPage at:" + start);
byte[] b = new byte[OggPageHeader.CAPTURE_PATTERN.length];
raf.read(b);
if (!(Arrays.equals(b, OggPageHeader.CAPTURE_PATTERN))) {
raf.seek(start);
if (AbstractID3v2Tag.isId3Tag(raf)) {
logger.warning(ErrorMessage.OGG_CONTAINS_ID3TAG.getMsg(raf.getFilePointer() - start));
raf.read(b);
if ((Arrays.equals(b, OggPageHeader.CAPTURE_PATTERN))) {
//Go to the end of the ID3 header
start = raf.getFilePointer() - OggPageHeader.CAPTURE_PATTERN.length;
}
} else {
throw new CannotReadException(ErrorMessage.OGG_HEADER_CANNOT_BE_FOUND.getMsg(new String(b)));
}
}
raf.seek(start + OggPageHeader.FIELD_PAGE_SEGMENTS_POS);
int pageSegments = raf.readByte() & 0xFF; //unsigned
raf.seek(start);
b = new byte[OggPageHeader.OGG_PAGE_HEADER_FIXED_LENGTH + pageSegments];
raf.read(b);
OggPageHeader pageHeader = new OggPageHeader(b);
pageHeader.setStartByte(start);
//Now just after PageHeader, ready for Packet Data
return pageHeader;
}
示例14: isId3v2Tag
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
private boolean isId3v2Tag() throws IOException {
raf.seek(0);
if (AbstractID3v2Tag.isId3Tag(raf)) {
logger.warning(ErrorMessage.FLAC_CONTAINS_ID3TAG.getMsg(raf.getFilePointer()));
//FLAC Stream immediately after end of id3 tag
if (isFlacHeader()) {
return true;
}
}
return false;
}
示例15: isId3v2Tag
import org.jaudiotagger.tag.id3.AbstractID3v2Tag; //导入依赖的package包/类
private boolean isId3v2Tag(final ByteBuffer headerData) throws IOException {
for (int i = 0; i < AbstractID3v2Tag.FIELD_TAGID_LENGTH; i++) {
if (headerData.get() != AbstractID3v2Tag.TAG_ID[i]) {
return false;
}
}
return true;
}