Additional information for OggVorbis files

Reading Data

VorbisComment supports multiple items with the same id for all fields except Artwork, conversly Mp4 does not support multiple fields except for the Artwork. If you want to retrieve all items with a particular id use


(VorbisCommentTag) ovtag = (VorbisCommentTag)f.getTag()
List list = ovtag.get(VorbisCommentFieldKey.PRODUCTNUMBER);
for(TagField field:list)
{
	System.out.println(field);
}	

The only common binary field is Artwork, OggVorbis does not actually support binary data so images are stored in two fields with the data base64 encoded (represents binary data using ascii) and the mimetype of the image in another field (although the mimetype field is not actually required to recreate the image). You can retrieve oggVorbis images in two ways, in the first method you decode the image yourself


(VorbisCommentTag) ovtag = (VorbisCommentTag)f.getTag();		
String imageData = ovtag.getFirst(VorbisCommentFieldKey.COVERART));
String mimetype  = ovtag.getFirst(VorbisCommentFieldKey.COVERARTMIME));
BufferedImage bi = ImageIO.read(ImageIO
            .createImageInputStream(new ByteArrayInputStream(Base64Coder.
                decode(imageData.toCharArray()))));

alternatively you can use the helper method


(VorbisCommentTag) ovtag = (VorbisCommentTag)f.getTag();	
byte[] newImageData = tag.getArtworkBinaryData();
BufferedImage bi = ImageIO.read(ImageIO.createImageInputStream(new ByteArrayInputStream(newImageData)));
			

Writing Data

You may wish to create a field, that is not listed in the general or audio specific enumeration. Vorbis Comments allow custom keys so you can create a custom field as follows

	
oggTag.set(oggTag.createTagField("VOLINIST,"Sarah Curtis"));

OggVorbis does not actually support binary data so images are stored in two fields with the data base64 encoded (represents binary data using ascii) and the mimetype of the image in another field (although the mimetype field is not actually required to recreate the image). You can create oggVorbis images in two ways, in the first method you encode the image yourself


RandomAccessFile imageFile = new RandomAccessFile(new File(coverart.png","r");
byte[] imagedata = new byte[(int)imageFile.length()];
imageFile.read(imagedata);
char[] testdata = Base64Coder.encode(imagedata);
String base64image = new String(testdata);
tag.set(tag.createTagField(VorbisCommentFieldKey.COVERART,base64image));
tag.set(tag.createTagField(VorbisCommentFieldKey.COVERARTMIME,"image/png"));
f.commit();

alternatively you can use the helper method


RandomAccessFile imageFile = new RandomAccessFile(new File(coverart.png","r");
byte[] imagedata = new byte[(int)imageFile.length()];
imageFile.read(imagedata);
tag.setArtworkField(imagedata,"image/png");
f.commit();