HapticGenerator
bookmark_borderbookmark
Stay organized with collections
Save and categorize content based on your preferences.
public
class
HapticGenerator
extends AudioEffect
implements
AutoCloseable
Haptic Generator(HG).
HG is an audio post-processor which generates haptic data based on the audio channels. The
generated haptic data is sent along with audio data down to the audio HAL, which will require the
device to support audio-coupled-haptic playback. In that case, the effect will only be created on
device supporting audio-coupled-haptic playback. Call HapticGenerator.isAvailable()
to
check if the device supports this effect.
An application can create a HapticGenerator object to initiate and control this audio effect
in the audio framework.
To attach the HapticGenerator to a particular AudioTrack or MediaPlayer, specify the audio
session ID of this AudioTrack or MediaPlayer when constructing the HapticGenerator.
See MediaPlayer.getAudioSessionId()
for details on audio sessions.
See AudioEffect
class for more details on controlling audio
effects.
Summary
Public methods |
void
|
close()
Release the resources that are held by the effect.
|
static
HapticGenerator
|
create(int audioSession)
Creates a HapticGenerator and attaches it to the given audio session.
|
static
boolean
|
isAvailable()
|
void
|
release()
Releases the native AudioEffect resources.
|
int
|
setEnabled(boolean enabled)
Enable or disable the effect.
|
Inherited methods |
From class
android.media.audiofx.AudioEffect
|
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait(long timeoutMillis, int nanos)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait(long timeoutMillis)
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted, or until a
certain amount of real time has elapsed.
|
final
void
|
wait()
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted.
|
|
From interface
java.lang.AutoCloseable
abstract
void
|
close()
Closes this resource, relinquishing any underlying resources.
|
|
Public methods
close
public void close ()
Release the resources that are held by the effect.
create
public static HapticGenerator create (int audioSession)
Creates a HapticGenerator and attaches it to the given audio session.
Use AudioTrack.getAudioSessionId()
or
MediaPlayer.getAudioSessionId()
to
apply this effect on specific AudioTrack or MediaPlayer instance.
Parameters |
audioSession |
int : system wide unique audio session identifier. The HapticGenerator will be
applied to the players with the same audio session. |
Returns |
HapticGenerator |
HapticGenerator created or null if the device does not support HapticGenerator or
the audio session is invalid. |
isAvailable
public static boolean isAvailable ()
Returns |
boolean |
true if the HapticGenerator is available on the device. |
release
public void release ()
Releases the native AudioEffect resources.
setEnabled
public int setEnabled (boolean enabled)
Enable or disable the effect. The effect can only be enabled if the caller has the
Manifest.permission.VIBRATE
permission.
Parameters |
enabled |
boolean : the requested enable state |