playEffect method

  1. @override
Future<void> playEffect(
  1. int soundId,
  2. String filePath,
  3. int loopCount,
  4. double pitch,
  5. double pan,
  6. double gain,
  7. bool publish,
)

Plays a specified local or online audio effect file.

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.

To play multiple audio effect files simultaneously, call this method multiple times with different soundIds and filePaths. 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 RtcEngineEventHandler.audioEffectFinished callback.

Parameter soundId ID of the specified audio effect. Each audio effect has a unique ID. If you preloaded the audio effect into the memory through the RtcEngine.preloadEffect method, ensure that the soundID value is set to the same value as in the RtcEngine.preloadEffect method.

Parameter filePath The absolute file path (including the suffixes of the filename) of the audio effect file or the URL of the online audio effect file. For example, /sdcard/emulated/0/audio.mp4. Supported audio formats: mp3, mp4, m4a, aac. 3gp, mkv, and wav.

Parameter loopCount Sets the number of times the audio effect loops:

Parameter pitch Sets the 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.

Parameter pan Sets the spatial position of the audio effect. The value ranges between -1.0 and 1.0.

  • 0.0: The audio effect shows ahead.
  • 1.0: The audio effect shows on the right.
  • -1.0: The audio effect shows on the left.

Parameter gain Sets 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.

Parameter publish Set whether or not to publish the specified audio effect to the remote stream:

  • true: The locally played audio effect is published to the Cloud and the remote users can hear it.
  • false: The locally played audio effect is not published to the Cloud and the remote users cannot hear it.

Implementation

@override
Future<void> playEffect(int soundId, String filePath, int loopCount,
    double pitch, double pan, double gain, bool publish) {
  return _invokeMethod('playEffect', {
    'soundId': soundId,
    'filePath': filePath,
    'loopCount': loopCount,
    'pitch': pitch,
    'pan': pan,
    'gain': gain,
    'publish': publish
  });
}