Agora Java API Reference for Android
io.agora.rtc.IAudioEffectManager Interface Reference

Public Member Functions

double getEffectsVolume ()
 
int setEffectsVolume (double volume)
 
int setVolumeOfEffect (int soundId, double volume)
 
int playEffect (int soundId, String filePath, int loop, double pitch, double pan, double gain)
 
int playEffect (int soundId, String filePath, int loopCount, double pitch, double pan, double gain, boolean publish)
 
int playEffect (int soundId, String filePath, int loopCount, double pitch, double pan, double gain, boolean publish, int startPos)
 
int stopEffect (int soundId)
 
int stopAllEffects ()
 
int preloadEffect (int soundId, String filePath)
 
int unloadEffect (int soundId)
 
int pauseEffect (int soundId)
 
int pauseAllEffects ()
 
int resumeEffect (int soundId)
 
int resumeAllEffects ()
 
int getEffectCurrentPosition (int soundId)
 
int setEffectPosition (int soundId, int pos)
 
int getEffectDuration (String filePath)
 
int startRhythmPlayer (String sound1, String sound2, AgoraRhythmPlayerConfig config)
 
int stopRhythmPlayer ()
 
int configRhythmPlayer (AgoraRhythmPlayerConfig config)
 

Detailed Description

Provides the methods to manage the audio effects.

Member Function Documentation

◆ getEffectsVolume()

double io.agora.rtc.IAudioEffectManager.getEffectsVolume ( )

Gets the volume of the audio effects.

Ensure that this method is called after playEffect.

The value ranges between 0.0 and 100.0.

Returns
  • Returns the volume, if the method call is successful.
  • < 0: Failure.

◆ setEffectsVolume()

int io.agora.rtc.IAudioEffectManager.setEffectsVolume ( double  volume)

Sets the volume of the audio effects.

Ensure that this method is called after playEffect.

Parameters
volumeVolume of the audio effects. The value ranges between 0.0 and 100.0 (default).
Returns
  • 0: Success.
  • < 0: Failure.

◆ setVolumeOfEffect()

int io.agora.rtc.IAudioEffectManager.setVolumeOfEffect ( int  soundId,
double  volume 
)

Sets the volume of a specified audio effect.

Ensure that this method is called after playEffect.

Parameters
soundIdID of the audio effect. Each audio effect has a unique ID.
volumeVolume of the audio effect. The value ranges between 0.0 and 100.0 (default).
Returns
  • 0: Success.
  • < 0: Failure.

◆ playEffect() [1/3]

int io.agora.rtc.IAudioEffectManager.playEffect ( int  soundId,
String  filePath,
int  loop,
double  pitch,
double  pan,
double  gain 
)

Plays a specified audio effect.

Deprecated:
This method is deprecated. We recommend using the playEffect[3/3] method to play the local audio effect.
Note
  • To play an online file for which the URL address starts with http, you need to add android:usesCleartextTraffic="true" to the /app/Manifests/AndroidManifest.xml file.
  • To use playEffect to play an online audio effect file, Agora recommends that you cache the online audio effect file to your local device, call preloadEffect, to preload the cached audio effect file into memory, and then call playEffect to play the audio effect. Otherwise, you can experience playback failures and silence due to online audio effect file loading timeouts or loading failures.
Parameters
soundIdID of the specified audio effect. Each audio effect has a unique ID. If the audio effect is preloaded into the memory through the preloadEffect method, ensure that the soundID value is set to the same value as in the preloadEffect method.
filePathAbsolute file path of the audio effect file.
loopSets the number of times the audio effect loops:
  • ≥ 0: The number of loops. For example, 1 means loop one time, which means play the audio effect two times in total.
  • -1: Play the audio effect in an indefinite loop.
pitchPitch of the audio effect. The value ranges between 0.5 and 2. The default value is 1 (no change to the pitch). The lower the value, the lower the pitch.
panSpatial position of the audio effect. The value ranges between -1.0 and 1.0.
  • 0.0: The audio effect displays ahead.
  • 1.0: The audio effect displays to the right.
  • -1.0: The audio effect displays to the left.
gainVolume of the audio effect. The value ranges between 0.0 and 100,0. The default value is 100.0. The lower the value, the lower the volume of the audio effect.
Returns
  • 0: Success.
  • < 0: Failure.

◆ playEffect() [2/3]

int io.agora.rtc.IAudioEffectManager.playEffect ( int  soundId,
String  filePath,
int  loopCount,
double  pitch,
double  pan,
double  gain,
boolean  publish 
)

Plays a specified local or online audio effect file.

Deprecated:
Deprecated from v3.4.0. Use playEffect[3/3] instead.

With this method, you can set the loop count, pitch, pan, and gain of the audio effect file and whether the remote user can hear the audio effect.

Ensure that you call this method after joining a channel. To play multiple audio effect files simultaneously, call this method multiple times with different soundId and filePath. We recommend playing no more than three audio effect files at the same time.

When the audio effect file playback is finished, the SDK triggers the onAudioEffectFinished callback.

Note
  • For the audio file formats supported by this method, see What formats of audio files does the Agora RTC SDK support.
  • To play an online file for which the URL address starts with http, you need to add android:usesCleartextTraffic="true" to the /app/Manifests/AndroidManifest.xml file.
  • To use playEffect to play an online audio effect file, Agora recommends that you cache the online audio effect file to your local device, call preloadEffect, to preload the cached audio effect file into memory, and then call playEffect to play the audio effect. Otherwise, you can experience playback failures and silence due to online audio effect file loading timeouts or loading failures.
Parameters
soundIdID of the specified audio effect. Each audio effect has a unique ID. If the audio effect is preloaded into the memory through the preloadEffect method, ensure that the soundID value is set to the same value as in the preloadEffect method.
filePathThe file path, including the filename extensions. To access an online file, Agora supports using a URL address; to access a local file, Agora supports using a URI address, an absolute path, or a path that starts with /assets/. Note: You might encounter permission issues if you use an absolute path to access a local file, so Agora recommends using a URI address instead. For example: "content://com.android.providers.media.documents/document/audio%3A14441". If you preloaded an audio effect into memory by calling preloadEffect, ensure that this parameter is set to the same value as in preloadEffect.
loopCountThe number of times the audio effect loops:
  • ≥ 0: The number of loops. For example, 1 means loop one time, which means play the audio effect two times in total.
  • -1: Play the audio effect in an indefinite loop.
pitchThe pitch of the audio effect. The value ranges between 0.5 and 2. The default value is 1 (no change to the pitch). The lower the value, the lower the pitch.
panThe spatial position of the audio effect. The value ranges between -1.0 and 1.0.
  • 0.0: The audio effect displays ahead.
  • 1.0: The audio effect displays to the right.
  • -1.0: The audio effect displays to the left.
gainSets the volume of the audio effect. The value ranges between 0.0 and 100,0. The default value is 100.0. The lower the value, the lower the volume of the audio effect.
publishSets whether to publish the specified audio effect to the remote stream:
  • true: The locally played audio effect is published to the Agora Cloud and the remote users can hear it.
  • false: The locally played audio effect is not published to the Agora Cloud and the remote users cannot hear it.
Returns
  • 0: Success.
  • < 0: Failure.

◆ playEffect() [3/3]

int io.agora.rtc.IAudioEffectManager.playEffect ( int  soundId,
String  filePath,
int  loopCount,
double  pitch,
double  pan,
double  gain,
boolean  publish,
int  startPos 
)

Plays a specified local or online audio effect file.

Since
v3.4.0

To play multiple audio effect files at the same time, call this method multiple times with different soundId and filePath values. For the best user experience, Agora recommends playing no more than three audio effect files at the same time.

After completing playing an audio effect file, the SDK triggers the onAudioEffectFinished callback.

Note
  • Call this method after joining a channel.
  • For the audio file formats supported by this method, see What formats of audio files does the Agora RTC SDK support.
  • To play an online file for which the URL address starts with http, you need to add android:usesCleartextTraffic="true" to the /app/Manifests/AndroidManifest.xml file.
  • To use playEffect to play an online audio effect file, Agora recommends that you cache the online audio effect file to your local device, call preloadEffect, to preload the cached audio effect file into memory, and then call playEffect to play the audio effect. Otherwise, you can experience playback failures and silence due to online audio effect file loading timeouts or loading failures.
Parameters
soundIdAudio effect ID. The ID of each audio effect file is unique. If you preloaded an audio effect into memory by calling preloadEffect, ensure that this parameter is set to the same value as in preloadEffect.
filePathThe file path, including the filename extensions. To access an online file, Agora supports using a URL address; to access a local file, Agora supports using a URI address, an absolute path, or a path that starts with /assets/. Note: You might encounter permission issues if you use an absolute path to access a local file, so Agora recommends using a URI address instead. For example: "content://com.android.providers.media.documents/document/audio%3A14441". If you preloaded an audio effect into memory by calling preloadEffect, ensure that this parameter is set to the same value as in preloadEffect.
loopCountThe number of times the audio effect loops:
  • ≥ 0: The number of loops. For example, 1 means loop one time, which means play the audio effect two times in total.
  • -1: Play the audio effect in an indefinite loop.
pitchThe pitch of the audio effect. The range is 0.5 to 2.0. The default value is 1.0, which means the original pitch. The lower the value, the lower the pitch.
panThe spatial position of the audio effect. The range is -1.0 to 1.0. For example:
  • -1.0: The audio effect occurs on the left.
  • 0.0: The audio effect occurs in the front.
  • 1.0: The audio effect occurs on the right.
gainThe volume of the audio effect. The range is 0.0 to 100.0. The default value is 100.0, which means the original volume. The smaller the value, the less the gain.
publishWhether to publish the audio effect to the remote users:
  • true: Publish. Both the local user and remote users can hear the audio effect.
  • false: Do not publish. Only the local user can hear the audio effect.
startPosThe playback position (ms) of the audio effect file.
Returns
  • 0: Success.
  • < 0: Failure.

◆ stopEffect()

int io.agora.rtc.IAudioEffectManager.stopEffect ( int  soundId)

Stops playing a specified audio effect.

Parameters
soundIdID of the specified audio effect. Each audio effect has a unique ID.
Note
If you preloaded the audio effect into the memory through the preloadEffect method, ensure that the soundID value is set to the same value as in the preloadEffect method.
Returns
  • 0: Success.
  • < 0: Failure.

◆ stopAllEffects()

int io.agora.rtc.IAudioEffectManager.stopAllEffects ( )

Stops playing all audio effects.

Returns
  • 0: Success.
  • < 0: Failure.

◆ preloadEffect()

int io.agora.rtc.IAudioEffectManager.preloadEffect ( int  soundId,
String  filePath 
)

Preloads a specified audio effect file into the memory.

Note
  • This method does not support online audio effect files.
  • For the audio file formats supported by this method, see What formats of audio files does the Agora RTC SDK support.
  • To ensure smooth communication, limit the size of the audio effect file.
  • You can call this method either before or after joining a channel.
Parameters
soundIdID of the audio effect. Each audio effect has a unique ID.
filePathThe file path of a local file, including the filename extensions. Agora supports using a URI address, an absolute path, or a path that starts with /assets/. Note: You might encounter permission issues if you use an absolute path to access a local file, so Agora recommends using a URI address instead. For example: "content://com.android.providers.media.documents/document/audio%3A14441".
Returns
  • 0: Success.
  • < 0: Failure.

◆ unloadEffect()

int io.agora.rtc.IAudioEffectManager.unloadEffect ( int  soundId)

Releases a specified preloaded audio effect from the memory.

Parameters
soundIdID of the audio effect. Each audio effect has a unique ID.
Returns
  • 0: Success.
  • < 0: Failure.

◆ pauseEffect()

int io.agora.rtc.IAudioEffectManager.pauseEffect ( int  soundId)

Pauses a specified audio effect.

Parameters
soundIdID of the audio effect. Each audio effect has a unique ID.
Returns
  • 0: Success.
  • < 0: Failure.

◆ pauseAllEffects()

int io.agora.rtc.IAudioEffectManager.pauseAllEffects ( )

Pauses all audio effects.

Returns
  • 0: Success.
  • < 0: Failure.

◆ resumeEffect()

int io.agora.rtc.IAudioEffectManager.resumeEffect ( int  soundId)

Resumes playing a specified audio effect.

Parameters
soundIdID of the audio effect. Each audio effect has a unique ID.
Returns
  • 0: Success.
  • < 0: Failure.

◆ resumeAllEffects()

int io.agora.rtc.IAudioEffectManager.resumeAllEffects ( )

Resumes playing all audio effects.

Returns
  • 0: Success.
  • < 0: Failure.

◆ getEffectCurrentPosition()

int io.agora.rtc.IAudioEffectManager.getEffectCurrentPosition ( int  soundId)

Gets the playback position of the audio effect file.

Since
v3.4.0
Note
Call this method after playEffect.
Parameters
soundIdAudio effect ID. Ensure that this parameter is set to the same value as in playEffect.
Returns
  • ≥ 0: A successful method call. Returns the playback position (ms) of the specified audio effect file.
  • < 0: Failure.

◆ setEffectPosition()

int io.agora.rtc.IAudioEffectManager.setEffectPosition ( int  soundId,
int  pos 
)

Sets the playback position of an audio effect file.

Since
v3.4.0

After a successful setting, the local audio effect file starts playing at the specified position.

Note
Call this method after playEffect.
Parameters
soundIdAudio effect ID. Ensure that this parameter is set to the same value as in playEffect.
posThe playback position (ms) of the audio effect file.
Returns
  • 0: Success.
  • < 0: Failure.

◆ getEffectDuration()

int io.agora.rtc.IAudioEffectManager.getEffectDuration ( String  filePath)

Gets the information of a specified audio file.

Since
v3.4.0

After calling this method successfully, the SDK triggers the onRequestAudioFileInfo callback to report the information of an audio file, such as audio duration. You can call this method multiple times to get the information of multiple audio files.

Note
  • Call this method after joining a channel.
  • For the audio file formats supported by this method, see What formats of audio files does the Agora RTC SDK support.
  • As of v3.7.0, the behavior of getEffectDuration has changed from getting the duration of a specified audio effect file to getting the information of a specified audio file.
Parameters
filePathThe file path, including the filename extensions. To access an online file, Agora supports using a URL address; to access a local file, Agora supports using a URI address, an absolute path, or a path that starts with /assets/. You might encounter permission issues if you use an absolute path to access a local file, so Agora recommends using a URI address instead. For example: content://com.android.providers.media.documents/document/audio%3A14441.
Returns
  • 0: Success.
  • < 0: Failure.

◆ startRhythmPlayer()

int io.agora.rtc.IAudioEffectManager.startRhythmPlayer ( String  sound1,
String  sound2,
AgoraRhythmPlayerConfig  config 
)

Enables the virtual metronome.

Since
v3.4.0

In music education, physical education, and other scenarios, teachers often need to use a metronome so that students can practice at the correct tempo. A meter is composed of a downbeat and some number of upbeats (including zero). The first beat of each measure is called the downbeat, and the rest are called the upbeats. In this method, you need to set the paths of the upbeat and downbeat files, the number of beats per measure, the tempo, and whether to send the sound of the metronome to remote users.

Note
  • After enabling the virtual metronome, the SDK plays the specified files from the beginning and controls the beat duration according to the value you set in beatsPerMinute. If the file duration exceeds the beat duration, the SDK only plays the audio within the beat duration.
  • For the audio file formats supported by this method, see What formats of audio files does the Agora RTC SDK support.
Parameters
sound1The absolute path (including the filename extensions) of the file for the downbeat. For example: /sdcard/emulated/0/audio.mp4.
sound2The absolute path (including the filename extensions) of the file for the upbeats. For example: /sdcard/emulated/0/audio.mp4.
configThe metronome configuration. See AgoraRhythmPlayerConfig.
Returns
  • 0: Success.
  • < 0: Failure.

◆ stopRhythmPlayer()

int io.agora.rtc.IAudioEffectManager.stopRhythmPlayer ( )

Disables the virtual metronome.

Since
v3.4.0

After calling startRhythmPlayer, you can call this method to disable the virtual metronome.

Returns
  • 0: Success.
  • < 0: Failure.

◆ configRhythmPlayer()

int io.agora.rtc.IAudioEffectManager.configRhythmPlayer ( AgoraRhythmPlayerConfig  config)

Configures the virtual metronome.

Since
v3.4.0

After calling startRhythmPlayer, you can call this method to reconfigure the virtual metronome.

Note
After reconfiguring the virtual metronome, the SDK plays the specified files from the beginning and controls the beat duration according to the value you set in beatsPerMinute. If the file duration exceeds the beat duration, the SDK only plays the audio within the beat duration.
Parameters
configThe metronome configuration. See AgoraRhythmPlayerConfig.
Returns
  • 0: Success.
  • < 0: Failure.