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.
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:
Parameter Type Description path String Resource path of the audio file, e.g., /assets/audio/music.mp3
mode RCRTCAudioMixingMode Mixing 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 operationplayBack boolean Whether to play the audio file after calling this method loopCount int loopCount > 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:
Parameter Type Description path String Absolute local path of the audio file mode RCRTCAudioMixingMode Mixing 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 playBack boolean Whether to play the audio file after calling this method loopCount int loopCount > 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:
Parameter Type Description volume int Mixing volume (remote user's audio level), range: 0–100 -
Example:
engine.adjustAudioMixingVolume(80);
Adjust Playback Volume
-
Parameters:
Parameter Type Description volume int Playback volume (local user's audio level), range: 0–100 -
Example:
engine.adjustAudioMixingPlaybackVolume(80);
Get Audio Mixing Duration
-
Return value:
Type Description int Total 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:
Type Description double Current 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:
Parameter Type Description position double Mixing 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
};