|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectezvcard.types.VCardType
ezvcard.types.BinaryType<SoundTypeParameter>
ezvcard.types.SoundType
public class SoundType
A sound to attach to the vCard, such as a pronunciation of the person's name.
Adding a sound
VCard vcard = new VCard(); //URL SoundType sound = new SoundType("http://www.mywebsite.com/myname.ogg", SoundTypeParameter.OGG); vcard.addSound(sound); //binary data byte data[] = ... sound = new SoundType(data, SoundTypeParameter.OGG); vcard.addSound(sound); //if "SoundTypeParameter" does not have the pre-defined constant that you need, then create a new instance //arg 1: the value of the 2.1/3.0 TYPE parameter //arg 2: the value to use for the 4.0 MEDIATYPE parameter and for 4.0 data URIs //arg 3: the file extension of the data type (optional) SoundTypeParameter param = new SoundTypeParameter("wav", "audio/wav", "wav"); sound = new SoundType("http://www.mywebsite.com/myname.wav", SoundTypeParameter.WAV); vcard.addSound(sound);
Getting the sounds
VCard vcard = ... int fileCount = 0; for (SoundType sound : vcard.getSounds()){ //the sound will have either a URL or a binary data if (sound.getData() == null){ System.out.println("Sound URL: " + sound.getUrl()); } else { SoundTypeParameter type = sound.getContentType(); if (type == null) { //the vCard may not have any content type data associated with the sound System.out.println("Saving a sound file..."); } else { System.out.println("Saving a \"" + type.getMediaType() + "\" file..."); } String folder; if (type == SoundTypeParameter.OGG){ //it is safe to use "==" instead of "equals()" folder = "ogg-files"; } else { folder = "sound-files"; } byte data[] = sound.getData(); String filename = "sound" + fileCount; if (type != null && type.getExtension() != null){ filename += "." + type.getExtension(); } OutputStream out = new FileOutputStream(new File(folder, filename)); out.write(data); out.close(); fileCount++; } }
vCard property name: SOUND
vCard versions: 2.1, 3.0, 4.0
Field Summary | |
---|---|
static String |
NAME
|
Fields inherited from class ezvcard.types.BinaryType |
---|
contentType, data, url |
Fields inherited from class ezvcard.types.VCardType |
---|
group, subTypes, typeName |
Constructor Summary | |
---|---|
SoundType()
|
|
SoundType(byte[] data,
SoundTypeParameter type)
|
|
SoundType(File file,
SoundTypeParameter type)
|
|
SoundType(InputStream in,
SoundTypeParameter type)
|
|
SoundType(String url,
SoundTypeParameter type)
|
Method Summary | |
---|---|
protected SoundTypeParameter |
buildMediaTypeObj(String mediaType)
Builds a MediaTypeParameter object based on the information in
the MEDIATYPE parameter or data URI of 4.0 vCards. |
protected SoundTypeParameter |
buildTypeObj(String type)
Builds a MediaTypeParameter object based on the value of the TYPE
parameter in 2.1/3.0 vCards. |
protected void |
doUnmarshalHtml(HCardElement element,
List<String> warnings)
Unmarshals the type from an hCard (HTML document). |
String |
getLanguage()
Gets the language. |
void |
setLanguage(String language)
Sets the language. |
Methods inherited from class ezvcard.types.BinaryType |
---|
addPid, cannotUnmarshalValue, doMarshalSubTypes, doMarshalText, doMarshalXml, doUnmarshalText, doUnmarshalXml, getAltId, getContentType, getData, getPids, getPref, getType, getUrl, removePids, setAltId, setContentType, setData, setPref, setType, setUrl |
Methods inherited from class ezvcard.types.VCardType |
---|
compareTo, getGroup, getQName, getSubTypes, getSupportedVersions, getTypeName, marshalSubTypes, marshalText, marshalXml, setGroup, unmarshalHtml, unmarshalText, unmarshalXml |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
public static final String NAME
Constructor Detail |
---|
public SoundType()
public SoundType(String url, SoundTypeParameter type)
url
- the URL to the sound filetype
- the content type (e.g. OGG)public SoundType(byte[] data, SoundTypeParameter type)
data
- the binary data of the sound filetype
- the content type (e.g. OGG)public SoundType(InputStream in, SoundTypeParameter type) throws IOException
in
- an input stream to the binary data (will be closed)type
- the content type (e.g. OGG)
IOException
- if there's a problem reading from the input streampublic SoundType(File file, SoundTypeParameter type) throws IOException
file
- the sound filetype
- the content type (e.g. OGG)
IOException
- if there's a problem reading from the fileMethod Detail |
---|
public String getLanguage()
VCardSubTypes.getLanguage()
public void setLanguage(String language)
language
- the language or null to removeVCardSubTypes.setLanguage(java.lang.String)
protected SoundTypeParameter buildTypeObj(String type)
BinaryType
MediaTypeParameter
object based on the value of the TYPE
parameter in 2.1/3.0 vCards.
buildTypeObj
in class BinaryType<SoundTypeParameter>
type
- the TYPE value
protected SoundTypeParameter buildMediaTypeObj(String mediaType)
BinaryType
MediaTypeParameter
object based on the information in
the MEDIATYPE parameter or data URI of 4.0 vCards.
buildMediaTypeObj
in class BinaryType<SoundTypeParameter>
mediaType
- the media type string (e.g. "image/jpeg")
protected void doUnmarshalHtml(HCardElement element, List<String> warnings)
VCardType
doUnmarshalHtml
in class BinaryType<SoundTypeParameter>
element
- the HTML element that contains the type data.warnings
- allows the programmer to alert the user to any
note-worthy (but non-critical) issues that occurred during the
unmarshalling process
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |