public class AudioWaver extends Object
SystemCapability.Multimedia#AUDIO| 限定符和类型 | 类 | 说明 |
|---|---|---|
static interface |
AudioWaver.FrequencyDataObserver |
Provides an observer to listen for frequency-domain audio data.
|
static interface |
AudioWaver.WaveDataObserver |
Provides an observer to listen for time-domain audio data.
|
| 构造器 | 说明 |
|---|---|
AudioWaver(int sessionId,
String packageName) |
A constructor used to create a
AudioWaver instance. |
| 限定符和类型 | 方法 | 说明 |
|---|---|---|
static int |
getMaxDataSize() |
Obtains the maximum size allowed for audio data capturing.
|
static int |
getMinDataSize() |
Obtains the minimum size allowed for audio data capturing.
|
static int |
getMinInterval() |
Obtains the minimum interval allowed for audio data capturing.
|
void |
release() |
Releases audio visualization resources.
|
boolean |
setActivated(boolean activated) |
Activates or deactivates audio visualization.
|
boolean |
setDataSize(int size) |
Sets the size of audio data that can be captured.
|
boolean |
setFrequencyDataObserver(AudioWaver.FrequencyDataObserver observer,
int interval) |
Sets an observer to listen for the frequency-domain waveform data at frequencies around the specific frequency.
|
boolean |
setWaveDataObserver(AudioWaver.WaveDataObserver observer,
int interval) |
Sets an observer to listen for the time-domain waveform data at frequencies around the specific frequency.
|
public AudioWaver(int sessionId,
String packageName)
throws UnsupportedOperationException
AudioWaver instance.sessionId - Indicates the ID of an audio playback session.packageName - Indicates an application package name.UnsupportedOperationException - Throws this exception if initialization of this class fails.public void release()
public boolean setDataSize(int size)
Before calling this method, obtain the supported size range via getMinDataSize() and
getMaxDataSize() and ensure the data size set by this method is within the range. Otherwise, the
setting fails.
size - Indicates the audio data size to set.true if the setting is successful; returns false otherwise.public boolean setActivated(boolean activated)
activated - Specifies whether audio visualization will be activated. Value true means to activate
the feature, and false means the opposite.true if the operation is successful; returns false otherwise.public static int getMinDataSize()
The size of captured audio data must be within the allowed size range. For the maximum size allowed, see
getMaxDataSize().
public static int getMaxDataSize()
The size of captured audio data must be within the allowed size range. For the maximum size allowed, see
getMaxDataSize().
public static int getMinInterval()
The minimum interval is used when you call setWaveDataObserver(ohos.media.audio.AudioWaver.WaveDataObserver,int) and
setFrequencyDataObserver(ohos.media.audio.AudioWaver.FrequencyDataObserver,int) to ensure that the sampling interval is longer
than or equal to the minimum interval.
public boolean setWaveDataObserver(AudioWaver.WaveDataObserver observer, int interval)
observer - Indicates the observer to set.interval - Indicates the audio data capturing interval. You should use getMinInterval() to obtain
the minimum interval and ensure that interval is greater than or equal to the minimum
interval.true if the setting is successful; returns false otherwise.public boolean setFrequencyDataObserver(AudioWaver.FrequencyDataObserver observer, int interval)
observer - Indicates the observer to set.interval - Indicates the audio data capturing interval. You should use getMinInterval() to obtain
the minimum interval and ensure that interval is greater than or equal to the minimum
interval.true if the setting is successful; returns false otherwise.