ezvcard.property
Class Sound

java.lang.Object
  extended by ezvcard.property.VCardProperty
      extended by ezvcard.property.BinaryProperty<SoundType>
          extended by ezvcard.property.Sound
All Implemented Interfaces:
HasAltId, Comparable<VCardProperty>

public class Sound
extends BinaryProperty<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
 Sound sound = new Sound("http://www.mywebsite.com/myname.ogg", SoundType.OGG);
 vcard.addSound(sound);
 
 //binary data
 byte data[] = ...
 sound = new Sound(data, SoundType.OGG);
 vcard.addSound(sound);
 
 //if "SoundType" 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)
 SoundType param = new SoundType("wav", "audio/wav", "wav");
 sound = new Sound("http://www.mywebsite.com/myname.wav", SoundType.WAV);
 vcard.addSound(sound);
 

Getting the sounds

 VCard vcard = ...
 
 int fileCount = 0;
 for (Sound 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 {
     SoundType 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 == SoundType.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++;
   }
 }
 

Property name: SOUND

Supported versions: 2.1, 3.0, 4.0

Author:
Michael Angstadt

Field Summary
 
Fields inherited from class ezvcard.property.BinaryProperty
contentType, data, url
 
Fields inherited from class ezvcard.property.VCardProperty
group, parameters
 
Constructor Summary
Sound(byte[] data, SoundType type)
          Creates a sound property.
Sound(File file, SoundType type)
          Creates a sound property.
Sound(InputStream in, SoundType type)
          Creates a sound property.
Sound(String url, SoundType type)
          Creates a sound property.
 
Method Summary
 String getLanguage()
          Gets the language that the property value is written in.
 void setLanguage(String language)
          Sets the language that the property value is written in.
 
Methods inherited from class ezvcard.property.BinaryProperty
_validate, addPid, getAltId, getContentType, getData, getPids, getPref, getType, getUrl, removePids, setAltId, setContentType, setData, setPref, setType, setUrl
 
Methods inherited from class ezvcard.property.VCardProperty
_supportedVersions, addParameter, compareTo, getGroup, getParameter, getParameters, getParameters, getSupportedVersions, removeParameter, setGroup, setParameter, setParameters, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Sound

public Sound(String url,
             SoundType type)
Creates a sound property.

Parameters:
url - the URL to the sound file
type - the content type (e.g. OGG)

Sound

public Sound(byte[] data,
             SoundType type)
Creates a sound property.

Parameters:
data - the binary data of the sound file
type - the content type (e.g. OGG)

Sound

public Sound(InputStream in,
             SoundType type)
      throws IOException
Creates a sound property.

Parameters:
in - an input stream to the binary data (will be closed)
type - the content type (e.g. OGG)
Throws:
IOException - if there's a problem reading from the input stream

Sound

public Sound(File file,
             SoundType type)
      throws IOException
Creates a sound property.

Parameters:
file - the sound file
type - the content type (e.g. OGG)
Throws:
IOException - if there's a problem reading from the file
Method Detail

getLanguage

public String getLanguage()
Description copied from class: VCardProperty
Gets the language that the property value is written in.

Returns:
the language or null if not set
See Also:
VCardParameters.getLanguage()

setLanguage

public void setLanguage(String language)
Description copied from class: VCardProperty
Sets the language that the property value is written in.

Parameters:
language - the language or null to remove
See Also:
VCardParameters.setLanguage(java.lang.String)


Copyright © 2012-2014 Michael Angstadt. All Rights Reserved.