danger.audio
Class Format

java.lang.Object
  extended by danger.audio.Format


public class Format
extends Object

This class is used for file type determination, and file conversion


Nested Class Summary
static interface Format.Errors
           
static interface Format.RecordType
          Format.Type.WAV is the same as Format.RecordType.WAV for backward compatibility
static interface Format.Type
          Supported audio types are Format.Type
 
Field Summary
static int DEFAULT_AMR_ENCODE_RATE
          default encode rate for AMR.
 
Constructor Summary
Format()
           
 
Method Summary
static boolean canTranslate(int sourceType, int destType)
          Pass in a Format.Type.* for sourceType and destType.
static boolean canTranslate(int sourceType, int destType, int destEncodeRate)
           
static String determineMimeType(byte[] data)
          Given at least 4 bytes of header from a file, determine if its a valid file and return its MIME type as a String.
static int determineType(byte[] data)
          Given at least 4 bytes of header from a file, determine if its a valid file and return its type as one of Format.Type.
static int determineType(File file)
          Given a file, determine if it is a valid file and return its type as one of Format.Type.
static int determineTypeFromResource(int id, Application app)
          Given a resource ID, walk through the application resource file, then the system resource file looking for a sequence then a sound, and return a Format.Type.* value
static int getDefaultEncodeRate(int type)
          Return default encode rate for passed in audio type
static Metatag getMetaInfo(File file)
           
static String[] getMimeTypes()
          Return a String [] with all supported device MIME types.
static int getSoundProperties(byte[] data, SoundProperties input)
           
static boolean isTypeFileStreamable(int type)
          Pass in a Format.Type.* and this will return true if this format can stream with the Stream object - use with file based objects
static boolean isTypeSequence(int type)
          Pass in a Format.Type.* and this will return true if it is a Sequence object
static boolean isTypeSound(int type)
          Pass in a Format.Type.* and this will return true if it is a Sound object
static boolean isTypeStreamable(int type)
          Pass in a Format.Type.* and this will return true if this format can stream with the Stream object - use with memory based objects
static byte[] translate(int sourceType, byte[] sourceData, int destType, int destEncodeRate)
          Start an synchronous translation of sourceType file into destType if possible.
static int translateProgress()
          If a translation is in progress, return percentage finished 0 to 100
static int translateStart(int sourceType, byte[] sourceData, int destType, int destEncodeRate, Event complete, Event failed)
          Start an asynchronous translation of sourceType file into destType if possible.
static void translateStop()
          Stop current translation if in progress
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_AMR_ENCODE_RATE

public static final int DEFAULT_AMR_ENCODE_RATE
default encode rate for AMR. The value 0 means use VBR.

See Also:
Constant Field Values
Constructor Detail

Format

public Format()
Method Detail

determineMimeType

public static String determineMimeType(byte[] data)
Given at least 4 bytes of header from a file, determine if its a valid file and return its MIME type as a String. Can return null for unknown.


getMimeTypes

public static String[] getMimeTypes()
Return a String [] with all supported device MIME types.


determineType

public static int determineType(byte[] data)
Given at least 4 bytes of header from a file, determine if its a valid file and return its type as one of Format.Type.


determineType

public static int determineType(File file)
Given a file, determine if it is a valid file and return its type as one of Format.Type.


getMetaInfo

public static Metatag getMetaInfo(File file)

isTypeFileStreamable

public static boolean isTypeFileStreamable(int type)
Pass in a Format.Type.* and this will return true if this format can stream with the Stream object - use with file based objects


isTypeStreamable

public static boolean isTypeStreamable(int type)
Pass in a Format.Type.* and this will return true if this format can stream with the Stream object - use with memory based objects


isTypeSound

public static boolean isTypeSound(int type)
Pass in a Format.Type.* and this will return true if it is a Sound object


isTypeSequence

public static boolean isTypeSequence(int type)
Pass in a Format.Type.* and this will return true if it is a Sequence object


determineTypeFromResource

public static int determineTypeFromResource(int id,
                                            Application app)
Given a resource ID, walk through the application resource file, then the system resource file looking for a sequence then a sound, and return a Format.Type.* value


getSoundProperties

public static int getSoundProperties(byte[] data,
                                     SoundProperties input)

getDefaultEncodeRate

public static int getDefaultEncodeRate(int type)
Return default encode rate for passed in audio type


canTranslate

public static boolean canTranslate(int sourceType,
                                   int destType)
Pass in a Format.Type.* for sourceType and destType. This will return true, if the translator can convert between the two.


canTranslate

public static boolean canTranslate(int sourceType,
                                   int destType,
                                   int destEncodeRate)

translate

public static byte[] translate(int sourceType,
                               byte[] sourceData,
                               int destType,
                               int destEncodeRate)
Start an synchronous translation of sourceType file into destType if possible. Only do this in a seperate thread. Returns byte [] of encoded data or null if failed. OS: 3.0


translateStart

public static int translateStart(int sourceType,
                                 byte[] sourceData,
                                 int destType,
                                 int destEncodeRate,
                                 Event complete,
                                 Event failed)
Start an asynchronous translation of sourceType file into destType if possible. Returns Errors.* For sourceType pass in Format.Type.UNKNOWN if format not known. NOTE: For Format.Type.AMR: destEncodeRate can be 4750 to 12200. 0 is a special variable bit rate encoding that ranges from 4750 to 12200 depending upon the content provided.


translateStop

public static void translateStop()
Stop current translation if in progress


translateProgress

public static int translateProgress()
If a translation is in progress, return percentage finished 0 to 100