Skip to main content

Audio Mixing

The audio mixing feature allows mixing specified audio files with locally captured microphone audio data. Supported custom audio file formats include: MP3, AAC, M4A, and WAV.

On Android, apps must have granted the <uses-permission android:name="android.permission.READ_EXTERNAL_STORAGE" /> permission before calling this feature.
No special requirements apply to iOS.

tip

If audio mixing fails on Android 10 devices despite granted permissions, refer to the knowledge base article: Why can't Android 10 use startAudioMixing for audio mixing?

Audio Mixing from Assets Directory

  • Parameters:

    ParameterTypeDescription
    pathStringResource path of the audio file, e.g., /assets/audio/music.mp3
    modeRCRTCAudioMixingModeMixing mode:

    RCRTCAudioMixingMode.mix: Mixes audio file data with microphone-captured data before sending to remote users

    RCRTCAudioMixingMode.replace: Replaces microphone-captured data with audio file data before sending

    RCRTCAudioMixingMode.none: No operation
    playBackbooleanWhether to play the audio file after calling this method
    loopCountintloopCount > 0: Mixes audio in loops for the specified count
    loopCount = -1: Infinite loop
    Other values: Mixes audio once
  • Example:

    engine.startAudioMixingFromAssets(path, RCRTCAudioMixingMode.mix, true, -1);

Audio Mixing from Local Directory

  • Parameters:

    ParameterTypeDescription
    pathStringAbsolute local path of the audio file
    modeRCRTCAudioMixingModeMixing mode: RCRTCAudioMixingMode.mix: Mixes audio file data with microphone-captured data before sending, RCRTCAudioMixingMode.replace: Replaces microphone-captured data with audio file data before sending, RCRTCAudioMixingMode.none: No operation
    playBackbooleanWhether to play the audio file after calling this method
    loopCountintloopCount > 0: Mixes audio in loops for the specified count
    loopCount = -1: Infinite loop
    Other values: Mixes audio once
  • Example:

    engine.startAudioMixing(path, RCRTCAudioMixingMode.mix, true, -1);

Adjust Mixing Volume

  • Parameters:

    ParameterTypeDescription
    volumeintMixing volume (remote user's audio level), range: 0–100
  • Example:

    engine.adjustAudioMixingVolume(80);

Adjust Playback Volume

  • Parameters:

    ParameterTypeDescription
    volumeintPlayback volume (local user's audio level), range: 0–100
  • Example:

    engine.adjustAudioMixingPlaybackVolume(80);

Get Audio Mixing Duration

  • Return value:

    TypeDescription
    intTotal duration of the current audio mixing file in milliseconds. Returns a negative value if the call fails.
  • Example:

    int duration = await engine.getAudioMixingDuration();

Get Audio Mixing Progress

  • Return value:

    TypeDescription
    doubleCurrent mixing progress (range: 0–1.0). Returns a negative value if the call fails.
  • Example:

    double position = await engine.getAudioMixingPosition();

Set Audio Mixing Progress

  • Parameters:

    ParameterTypeDescription
    positiondoubleMixing progress (range: 0–1.0)
  • Example:

    /// Start mixing from the 20% position of the current file
    engine.setAudioMixingPosition(0.2);

Pause Audio Mixing

  • Example:

    engine.pauseAudioMixing();

Resume Audio Mixing

  • Example:

    engine.resumeAudioMixing();

Stop Audio Mixing

  • Example:

    engine.stopAudioMixing();

Set Audio Mixing Status Callback

Listeners for audio mixing start, pause, stop, and completion events.

  • Example:

    /// Set audio mixing start callback
    engine.onAudioMixingStarted = () {
    // Audio mixing started
    };

    /// Set audio mixing pause callback
    engine.onAudioMixingPaused = () {
    // Audio mixing paused
    };

    /// Set audio mixing stop callback
    engine.onAudioMixingStopped = () {
    // Audio mixing stopped
    };

    /// Set audio mixing completion callback
    engine.onAudioMixingFinished = () {
    // Audio mixing completed
    };