startAudioMixing method

  1. @override
Future<void> startAudioMixing(
  1. String filePath,
  2. bool loopback,
  3. bool replace,
  4. int cycle,
)

Starts playing and mixing the music file.

This method mixes the specified local or online audio file with the audio stream from the microphone, or replaces the microphone’s audio stream with the specified local or remote audio file. You can choose whether the other user can hear the local audio playback and specify the number of playback loops. When the audio mixing file playback finishes after calling this method, the SDK triggers the RtcEngineEventHandler.audioMixingFinished callback.

A successful startAudioMixing method call triggers the RtcEngineEventHandler.audioMixingStateChanged (AudioMixingStateCode.Playing) callback on the local client.

When the audio mixing file playback finishes, the SDK triggers the RtcEngineEventHandler.audioMixingStateChanged (AudioMixingStateCode.Stopped) callback on the local client.

Note

  • This method supports both Android and iOS. To use this method in Android, ensure that the Android device is v4.2 or later, and the API version is v16 or later.
  • Call this method when you are in the channel, otherwise it may cause issues.
  • If you want to play an online music file, ensure that the time interval between calling this method is more than 100 ms, or the AudioMixingErrorCode.TooFrequentCall error occurs.
  • If you want to play an online music file, does not recommend using the redirected URL address. Some Android devices may fail to open a redirected URL address.
  • If the local audio mixing file does not exist, or if the SDK does not support the file format or cannot access the music file URL, the SDK returns AudioMixingErrorCode.CanNotOpen.
  • If you call this method on an emulator, only the MP3 file format is supported.

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

  • If the path begins with /assets/, the audio file is in the /assets/ directory.
  • Otherwise, the audio file is in the absolute path.

Parameter loopback Sets which user can hear the audio mixing:

  • true: Only the local user can hear the audio mixing.
  • false: Both users can hear the audio mixing.

Parameter replace Sets the audio mixing content:

  • true: Only publish the specified audio file; the audio stream from the microphone is not published.
  • false: The local audio file is mixed with the audio stream from the microphone.

Parameter cycle Sets the number of playback loops:

  • Positive integer: Number of playback loops
  • -1: Infinite playback loops

Implementation

@override
Future<void> startAudioMixing(
    String filePath, bool loopback, bool replace, int cycle) {
  return _invokeMethod('startAudioMixing', {
    'filePath': filePath,
    'loopback': loopback,
    'replace': replace,
    'cycle': cycle
  });
}