danger.audio
Class AudioManager

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


public class AudioManager
extends Object


Field Summary
static int DEBUG_GENERAL
           
static int DEBUG_NONE
          debug level selectors.
static int DEBUG_PLAYABLE
           
static int DEBUG_SEQUENCE
           
static int DEBUG_SOUND
           
static int DEBUG_STREAM
           
static int DEBUG_SYSTEM
           
static int EIGHTH_SECOND
           
static int HALF_SECOND
           
static String kAudioRouteBluetoothPhone
           
static String kAudioRouteOldPhone
           
static String kAudioRouteOldPlayback
           
static String kAudioRouteOldRecord
           
static String kAudioRouteOldSpeakerPhone
           
static String kAudioRoutePhone
           
static String kAudioRoutePhoneHeadset
           
static String kAudioRoutePlaybackBluetooth
           
static String kAudioRoutePlaybackHeadset
           
static String kAudioRoutePlaybackSpeaker
           
static String kAudioRouteRecord
           
static String kAudioRouteRecordBluetooth
           
static String kAudioRouteRecordHeadset
           
static String kAudioRouteSilent
          audio route names
static String kAudioRouteSpeakerphone
           
static String kAudioRouteUnknown
           
static int MEDIA_ANY
          Media id used to query for any media playing.
static int MEDIA_NONE
          Media id used when no media is playing.
static int NOW
          time constants
static int ONE_SECOND
           
static int QUARTER_SECOND
           
 
Constructor Summary
AudioManager()
           
 
Method Summary
static boolean canCreateRecorder()
          If a Recorder can be created with createRecorder(), this will return true, otherwise false
static Recorder createRecorder()
          Create a new sound Recorder object.
static Sequence createSequence()
          Create a new Sequence object.
static Sequence createSequence(boolean autoDelete)
          Create a new Sequence object.
static Sequence createSequence(boolean autoDelete, int type)
          Create a new Sequence object.
static Sound createSound()
          Create a new Sound object.
static Sound createSound(boolean autoDelete)
          Create a new Sound object.
static Sound createSound(boolean autoDelete, int type)
          Create a new Sound object.
static Stream createStream()
          Create a new Stream object.
static Stream createStream(boolean autoDelete)
          Create a new Stream object.
static Stream createStream(boolean autoDelete, int type)
          Create a new Stream object.
static void eventAudio(Event event)
           
static String getCodecMimeType(int fileType)
          Return MIME type from passed in Format.Type.* which can be obtained from isCodecSupported
static int getCurrentAudioRoute()
          Get the current audio route
static int getDebugLevel()
          Returns current global debug level.
static int getFrameSnapshot(short[] left, short[] right)
          If startFrameSnapshot() has been called, and it returned true, then calls to getFrameSnapshot() will return a copy of the last audio buffer sent to the hardware.
static Bitmap getMediaStreamIcon(int id)
          Get the icon for the given media id.
static int getMediaStreamPlayerIDFromName(String name)
          Get the media id from the player name.
static String getMediaStreamPlayerName(int id)
          Get the name of the player from the media id.
static int getMediaStreamVolume(int id)
          Get the volume for the given stream.
static int getMixerRate()
          returns sample rate of audio mixer
static int getRecordMonitorLevel()
          Get record monitor level
static int getTime()
          get current tick in microseconds One thousand microseconds equal 1 millisecond.
static int getTimePlusEighthSecond()
           
static int getTimePlusHalfSecond()
           
static int getTimePlusOneSecond()
           
static int getTimePlusQuarterSecond()
           
static boolean includesDebugLevel(int level)
          Returns true if global debug level includes the specified level OS 3.0
static void initializeFromSysApp()
           
static void installImpl(danger.audio.AudioManagerImpl inImpl)
           
static boolean isActive()
          returns true, if audio system is generating audio
static boolean isBuiltIn()
          test to see if audio system is built into rom
static boolean isMediaPlayerRegistered(Listener listener)
           
static boolean isMediaStream(int id)
          Get the volume for the given stream.
static boolean isMediaStreamPlaying(int id)
          Returns true if the media stream with this id is playing.
static boolean isRecording()
          Are we recording?
static Object load(byte[] data)
          Given a byte stream, figure out what kind of audio file it is, if any, and load it.
static Object load(File file)
          Given a File, figure out what kind of audio file it is, if any, and load it.
static PlayableAudio load(File file, boolean autoDelete)
          Given a File, figure out what kind of audio file it is, if any, and load it, with the ability to determine whether it is auto-deleted or not.
static Object play(byte[] data)
          Given a byte stream, figure out what kind of audio file it is, if any, and play it.
static Object play(File file)
          Given a File, figure out what kind of audio file it is, if any, and play it.
static void playDTMFTone(char toneKey, int signalLengthInMS, int gapBetweenSignalInMS, int volume)
          play DTMF tones syncronously.
static void playDTMFToneAsync(char toneKey, int signalLengthInMS, int gapBetweenSignalInMS, int volume)
          play one DTMF tone asyncronously.
static void playDTMFToneString(String tones, int signalLengthInMS, int gapBetweenSignalInMS, int volume)
          play one DTMF tone syncronously.
static void playDTMFToneStringAsync(String tones, int signalLengthInMS, int gapBetweenSignalInMS, int volume)
          play DTMF tones asyncronously.
static boolean recognize(File file)
          Given a File, return whether or not the file is recognized as audio.
static void registerForAudioEvents(Listener inListener)
          Register a Listener object to receive audio events
static int registerMediaPlayer(Listener listener, String name, Bitmap icon)
          Register a media player to be controlled by the sound controls.
static void setDebugLevel(int level)
          Set the global debug level
static void setMediaStreamVolume(int id, int volume)
          Set the volume for the given stream.
static void start(Object object, int filters)
          Given an object created with AudioManager.play() or AudioManager.load() start it playing with a given ToneFilter
static boolean startFrameSnapshot()
          Turn on snapshot mode.
static void stop(Object object)
          Given an object created with AudioManager.play() or AudioManager.load() stop it from playing and destroy it.
static void stopFrameSnapshot()
          Call after finished capturing audio snapshots.
static void testTone(boolean status)
          turn on/off a test tone.
static void testToneFrequency(int frequency)
          When the tone is enabled, play this frequency.
static void unregisterForAudioEvents(Listener inListener)
          Unregister a Listener object to receive audio events
static void vibrate(int inDuration)
          -1 = on, 0 = off, > 0 = duration in milliseconds
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

kAudioRouteSilent

public static final String kAudioRouteSilent
audio route names

See Also:
Constant Field Values

kAudioRouteOldPlayback

public static final String kAudioRouteOldPlayback
See Also:
Constant Field Values

kAudioRouteOldRecord

public static final String kAudioRouteOldRecord
See Also:
Constant Field Values

kAudioRouteOldPhone

public static final String kAudioRouteOldPhone
See Also:
Constant Field Values

kAudioRouteOldSpeakerPhone

public static final String kAudioRouteOldSpeakerPhone
See Also:
Constant Field Values

kAudioRoutePlaybackSpeaker

public static final String kAudioRoutePlaybackSpeaker
See Also:
Constant Field Values

kAudioRoutePlaybackHeadset

public static final String kAudioRoutePlaybackHeadset
See Also:
Constant Field Values

kAudioRoutePlaybackBluetooth

public static final String kAudioRoutePlaybackBluetooth
See Also:
Constant Field Values

kAudioRoutePhone

public static final String kAudioRoutePhone
See Also:
Constant Field Values

kAudioRoutePhoneHeadset

public static final String kAudioRoutePhoneHeadset
See Also:
Constant Field Values

kAudioRouteSpeakerphone

public static final String kAudioRouteSpeakerphone
See Also:
Constant Field Values

kAudioRouteBluetoothPhone

public static final String kAudioRouteBluetoothPhone
See Also:
Constant Field Values

kAudioRouteRecord

public static final String kAudioRouteRecord
See Also:
Constant Field Values

kAudioRouteRecordHeadset

public static final String kAudioRouteRecordHeadset
See Also:
Constant Field Values

kAudioRouteRecordBluetooth

public static final String kAudioRouteRecordBluetooth
See Also:
Constant Field Values

kAudioRouteUnknown

public static final String kAudioRouteUnknown
See Also:
Constant Field Values

NOW

public static final int NOW
time constants

See Also:
Constant Field Values

ONE_SECOND

public static final int ONE_SECOND
See Also:
Constant Field Values

HALF_SECOND

public static final int HALF_SECOND
See Also:
Constant Field Values

QUARTER_SECOND

public static final int QUARTER_SECOND
See Also:
Constant Field Values

EIGHTH_SECOND

public static final int EIGHTH_SECOND
See Also:
Constant Field Values

DEBUG_NONE

public static final int DEBUG_NONE
debug level selectors. Use as values for setDebugLevel(). OS 3.0

See Also:
Constant Field Values

DEBUG_GENERAL

public static final int DEBUG_GENERAL
See Also:
Constant Field Values

DEBUG_SYSTEM

public static final int DEBUG_SYSTEM
See Also:
Constant Field Values

DEBUG_PLAYABLE

public static final int DEBUG_PLAYABLE
See Also:
Constant Field Values

DEBUG_SOUND

public static final int DEBUG_SOUND
See Also:
Constant Field Values

DEBUG_STREAM

public static final int DEBUG_STREAM
See Also:
Constant Field Values

DEBUG_SEQUENCE

public static final int DEBUG_SEQUENCE
See Also:
Constant Field Values

MEDIA_NONE

public static final int MEDIA_NONE
Media id used when no media is playing. OS: 3.0

See Also:
Constant Field Values

MEDIA_ANY

public static final int MEDIA_ANY
Media id used to query for any media playing. OS: 3.0

See Also:
Constant Field Values
Constructor Detail

AudioManager

public AudioManager()
Method Detail

installImpl

public static void installImpl(danger.audio.AudioManagerImpl inImpl)

initializeFromSysApp

public static void initializeFromSysApp()

isActive

public static boolean isActive()
returns true, if audio system is generating audio


isBuiltIn

public static boolean isBuiltIn()
test to see if audio system is built into rom


getMixerRate

public static int getMixerRate()
returns sample rate of audio mixer


setDebugLevel

public static void setDebugLevel(int level)
Set the global debug level


getDebugLevel

public static int getDebugLevel()
Returns current global debug level. If 0, then no debugging information is spewed


includesDebugLevel

public static boolean includesDebugLevel(int level)
Returns true if global debug level includes the specified level OS 3.0


vibrate

public static void vibrate(int inDuration)
-1 = on, 0 = off, > 0 = duration in milliseconds


playDTMFToneStringAsync

public static void playDTMFToneStringAsync(String tones,
                                           int signalLengthInMS,
                                           int gapBetweenSignalInMS,
                                           int volume)
play DTMF tones asyncronously.


playDTMFToneAsync

public static void playDTMFToneAsync(char toneKey,
                                     int signalLengthInMS,
                                     int gapBetweenSignalInMS,
                                     int volume)
play one DTMF tone asyncronously.


playDTMFTone

public static void playDTMFTone(char toneKey,
                                int signalLengthInMS,
                                int gapBetweenSignalInMS,
                                int volume)
play DTMF tones syncronously.


playDTMFToneString

public static void playDTMFToneString(String tones,
                                      int signalLengthInMS,
                                      int gapBetweenSignalInMS,
                                      int volume)
play one DTMF tone syncronously.


testToneFrequency

public static void testToneFrequency(int frequency)
When the tone is enabled, play this frequency. Only 1000 hz and 3000 hz are supported at the moment


testTone

public static void testTone(boolean status)
turn on/off a test tone. Takes over all audio


canCreateRecorder

public static boolean canCreateRecorder()
If a Recorder can be created with createRecorder(), this will return true, otherwise false


isRecording

public static boolean isRecording()
Are we recording?


getRecordMonitorLevel

public static int getRecordMonitorLevel()
Get record monitor level


createRecorder

public static Recorder createRecorder()
                               throws AudioException
Create a new sound Recorder object. Will throw an exception if not available.

Throws:
AudioException

createSequence

public static Sequence createSequence(boolean autoDelete,
                                      int type)
                               throws AudioException
Create a new Sequence object. Will throw an exception if audio not avaiable. autoDelete : true to garbage collect when the object has finished playing false to keep loaded. Do Sequence.destroy() prior to releasing last reference. If you do not, you'll create a memory leak. type : UNKNOWN_SEQUENCE, UNKNOWN_SOUND, META these are used to mark the sequence so that when calling stopAll() you can specific the type of sound to stop.

Throws:
AudioException

createSequence

public static Sequence createSequence(boolean autoDelete)
                               throws AudioException
Create a new Sequence object. Will throw an exception if audio not avaiable. autoDelete : true to garbage collect when the object has finished playing false to keep loaded. Do Sequence.destroy() prior to releasing last reference. If you do not, you'll create a memory leak.

Throws:
AudioException

createSequence

public static Sequence createSequence()
                               throws AudioException
Create a new Sequence object. Will throw an exception if audio not avaiable. Will autoDelete (garbage collect) when the sequence is finished playing.

Throws:
AudioException

createSound

public static Sound createSound(boolean autoDelete,
                                int type)
                         throws AudioException
Create a new Sound object. Will throw an exception if audio not avaiable. autoDelete : true to garbage collect when the object has finished playing false to keep loaded. Do Sound.destroy() prior to releasing last reference. If you do not, you'll create a memory leak. type : UNKNOWN_SEQUENCE, UNKNOWN_SOUND, META these are used to mark the sequence so that when calling stopAll() you can specific the type of sound to stop.

Throws:
AudioException

createSound

public static Sound createSound(boolean autoDelete)
                         throws AudioException
Create a new Sound object. Will throw an exception if audio not avaiable. autoDelete : true to garbage collect when the object has finished playing false to keep loaded. Do Sound.destroy() prior to releasing last reference. If you do not, you'll create a memory leak.

Throws:
AudioException

createSound

public static Sound createSound()
                         throws AudioException
Create a new Sound object. Will throw an exception if audio not avaiable. Will autoDelete (garbage collect) when the sequence is finished playing.

Throws:
AudioException

createStream

public static Stream createStream(boolean autoDelete,
                                  int type)
                           throws AudioException
Create a new Stream object. Will throw an exception if audio not avaiable. autoDelete : true to garbage collect when the object has finished playing false to keep loaded. Do Stream.destroy() prior to releasing last reference. If you do not, you'll create a memory leak. type : UNKNOWN_SEQUENCE, UNKNOWN_SOUND, META these are used to mark the sequence so that when calling stopAll() you can specific the type of sound to stop.

Throws:
AudioException

createStream

public static Stream createStream(boolean autoDelete)
                           throws AudioException
Create a new Stream object. Will throw an exception if audio not avaiable. autoDelete : true to garbage collect when the object has finished playing false to keep loaded. Do Stream.destroy() prior to releasing last reference. If you do not, you'll create a memory leak.

Throws:
AudioException

createStream

public static Stream createStream()
                           throws AudioException
Create a new Stream object. Will throw an exception if audio not avaiable. Will autoDelete (garbage collect) when the sequence is finished playing.

Throws:
AudioException

registerForAudioEvents

public static void registerForAudioEvents(Listener inListener)
Register a Listener object to receive audio events


unregisterForAudioEvents

public static void unregisterForAudioEvents(Listener inListener)
Unregister a Listener object to receive audio events


eventAudio

public static void eventAudio(Event event)

getCurrentAudioRoute

public static int getCurrentAudioRoute()
Get the current audio route


getCodecMimeType

public static String getCodecMimeType(int fileType)
Return MIME type from passed in Format.Type.* which can be obtained from isCodecSupported


startFrameSnapshot

public static boolean startFrameSnapshot()
Turn on snapshot mode. When called, if returns true, the every time you call getFrameSnapshot() you'll get a peek into the audio output bufffer. Call stopFrameSnapshot() to turn off mode. NOTE: This is not frame accurate. This is used for display only.


getFrameSnapshot

public static int getFrameSnapshot(short[] left,
                                   short[] right)
If startFrameSnapshot() has been called, and it returned true, then calls to getFrameSnapshot() will return a copy of the last audio buffer sent to the hardware.


stopFrameSnapshot

public static void stopFrameSnapshot()
Call after finished capturing audio snapshots.


getTime

public static int getTime()
get current tick in microseconds One thousand microseconds equal 1 millisecond. One thousand milliseconds equal 1 second. Sixty seconds equal 1 minute.


getTimePlusQuarterSecond

public static int getTimePlusQuarterSecond()

getTimePlusHalfSecond

public static int getTimePlusHalfSecond()

getTimePlusOneSecond

public static int getTimePlusOneSecond()

getTimePlusEighthSecond

public static int getTimePlusEighthSecond()

load

public static Object load(byte[] data)
Given a byte stream, figure out what kind of audio file it is, if any, and load it. Currently Format.isTypeStreamable returns true for AMR and mp3. Returns an Object that is either a Sound or a Sequence, or NULL if invalid data. Use instanceof Sound or instanceof Sequence to figure out what type of object returned. This sound/sequence will auto delete once its been played. If the media has loop points they will remain intact. Use Sequence.setLoops(0) or Sound.setSampleLoopPoints(0, 0) to clear the loop points.


load

public static Object load(File file)
Given a File, figure out what kind of audio file it is, if any, and load it. Currently Format.isTypeFileStreamable returns true for WAV, AIFF, AMR and mp3. Returns an Object that is either a Sound or a Sequence, or NULL if invalid data. Use instanceof Sound or instanceof Sequence to figure out what type of object returned. This sound/sequence will auto delete once its been played. If the media has loop points they will remain intact. Use Sequence.setLoops(0) or Sound.setSampleLoopPoints(0, 0) to clear the loop points.


recognize

public static boolean recognize(File file)
Given a File, return whether or not the file is recognized as audio.


load

public static PlayableAudio load(File file,
                                 boolean autoDelete)
Given a File, figure out what kind of audio file it is, if any, and load it, with the ability to determine whether it is auto-deleted or not. Object is returned as PlayableAudio.


play

public static Object play(byte[] data)
Given a byte stream, figure out what kind of audio file it is, if any, and play it. Currently Format.isTypeStreamable returns true for AMR and mp3. Returns an Object that is either a Sound or a Sequence, or NULL if invalid data. Use instanceof Sound or instanceof Sequence to figure out what type of object returned. This sound/sequence will auto delete once its been played. If the media has loop points they will remain intact. Use Sequence.setLoops(0) or Sound.setSampleLoopPoints(0, 0) to clear the loop points.


play

public static Object play(File file)
Given a File, figure out what kind of audio file it is, if any, and play it. Currently Format.isTypeFileStreamable returns true for WAV, AIFF, AMR and mp3. Returns an Object that is either a Sound or a Sequence, or NULL if invalid data. Use instanceof Sound or instanceof Sequence to figure out what type of object returned. This sound/sequence will auto delete once its been played. If the media has loop points they will remain intact. Use Sequence.setLoops(0) or Sound.setSampleLoopPoints(0, 0) to clear the loop points.


start

public static void start(Object object,
                         int filters)
Given an object created with AudioManager.play() or AudioManager.load() start it playing with a given ToneFilter


stop

public static void stop(Object object)
Given an object created with AudioManager.play() or AudioManager.load() stop it from playing and destroy it.


registerMediaPlayer

public static int registerMediaPlayer(Listener listener,
                                      String name,
                                      Bitmap icon)
Register a media player to be controlled by the sound controls. If your media stream is currently playing, and the user clicks the sound control buttons, your listener will receive an EventType.EVENT_AUDIO_MEDIA_VOLUME_CHANGE_REQUESTED event. The what field of the event contains the media id. The data field of the event contains the new volume value.

Parameters:
listener - non-null; The target listener.
icon - null-ok; The icon to use in the sound controls.
Returns:
A unique id for the registered media player. OS: 3.0

setMediaStreamVolume

public static void setMediaStreamVolume(int id,
                                        int volume)
Set the volume for the given stream.

Parameters:
id - The id of the media stream OS: 3.0

getMediaStreamVolume

public static int getMediaStreamVolume(int id)
Get the volume for the given stream.

Parameters:
id - The id of the media stream OS: 3.0

isMediaStreamPlaying

public static boolean isMediaStreamPlaying(int id)
Returns true if the media stream with this id is playing.

Parameters:
id - The id of a media stream - Use MEDIA_ANY to see if any media streams are playing.
Returns:
true if this media stream is playing, or false otherwise. OS: 3.0

getMediaStreamIcon

public static Bitmap getMediaStreamIcon(int id)
Get the icon for the given media id.

Parameters:
id - The id of a media stream.
Returns:
null-ok; The icon registered for the given media id. OS: 3.0

getMediaStreamPlayerName

public static String getMediaStreamPlayerName(int id)
Get the name of the player from the media id.

Parameters:
id - The id of a media stream.
Returns:
The name of the currently playing media player. OS: 3.0

getMediaStreamPlayerIDFromName

public static int getMediaStreamPlayerIDFromName(String name)
Get the media id from the player name.

Parameters:
The - media player name.
Returns:
The media stream id. OS: 3.0

isMediaStream

public static boolean isMediaStream(int id)
Get the volume for the given stream.

Parameters:
id - The id of the media stream OS: 3.0

isMediaPlayerRegistered

public static boolean isMediaPlayerRegistered(Listener listener)