# Audio mixing and sound effects (/en/realtime-media/broadcast-streaming/build/control-audio-and-devices/audio-mixing-and-sound-effects/react-native)

> For AI agents: see the complete documentation index at [llms.txt](/llms.txt).

Video SDK makes it simple for you to publish audio captured through the microphone to subscribers in a channel. In some real-time audio and video use-cases, such as games or karaoke, you need to play sound effects or mix in music files to enhance the atmosphere and add interest. Video SDK enables you to add sound effects and mix in pre-recorded audio.

      
  
      
  
      
  
      
  
      
  
      
  
      
    This page shows you how to implement audio mixing and playing sound effects in your app.

    ## Understand the tech [#understand-the-tech-6]

    Video SDK provides APIs that enable you to implement:

    * **Audio mixing**

      Mix in music file such as background music with microphone audio. Using this feature, you can play only one file at a time.

    * **Sound effects**

      Play audios with a short duration. For example, applause, cheers, or gunshots. You can play multiple sound effects at the same time.

    ## Prerequisites [#prerequisites-6]

    Ensure that you have:

    * Implemented the [SDK quickstart](../../index) in your project.

    * Audio files in one of the formats supported by the target development platform:
      * [Android](https://developer.android.com/media/platform/supported-formats)
      * [iOS](https://developer.apple.com/library/archive/documentation/AudioVideo/Conceptual/MultimediaPG/UsingAudio/UsingAudio.html#/apple_ref/doc/uid/TP40009767-CH2-SW28)

    ## Play sound effects and music [#play-sound-effects-and-music-5]

    This section shows you how to implement playing sound effects and add audio mixing in your app.

    To manage audio mixing and sound effects, Video SDK provides the following APIs:

    | Function                                    | Sound effect                                                                                                                     | Audio mixing                                                                                                                                                                                                         |
    | ------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
    | Play or stop playing a specific audio file  | `preloadEffect`<br /> `unloadEffect`<br /> `playEffect`<br /> `stopEffect`<br /> `stopAllEffects`                                | `startAudioMixing`<br /> `stopAudioMixing`                                                                                                                                                                           |
    | Pause or resume playing an audio file       | `pauseEffect`<br /> `pauseAllEffects`<br /> `resumeEffect`<br /> `resumeAllEffects`                                              | `pauseAudioMixing`<br /> `resumeAudioMixing`                                                                                                                                                                         |
    | Get and adjust playback position and volume | `setEffectPosition`<br /> `getEffectCurrentPosition`<br /> `getEffectsVolume`<br /> `setEffectsVolume`<br /> `setVolumeOfEffect` | `getAudioMixingCurrentPosition`<br /> `setAudioMixingPosition`<br /> `getAudioMixingPublishVolume`<br /> `adjustAudioMixingPublishVolume`<br /> `getAudioMixingPlayoutVolume`<br /> `adjustAudioMixingPlayoutVolume` |
    | Report playback status of audio files       | `onAudioEffectFinished`                                                                                                          | `onAudioMixingStateChanged`                                                                                                                                                                                          |

    ### Play sound effects [#play-sound-effects-5]

    After joining a channel, call `playEffect` to play the specified sound effect file. Call `playEffect` multiple times to set multiple sound effect IDs and play multiple files simultaneously. When the playback is finished, the SDK triggers the `onAudioEffectFinished` callback.

    Refer to the following code example:

    ```typescript
    // Register the sound effect playback completion callback
    const EventHandler = {
      onAudioEffectFinished: (soundId) => {
        console.log(`soundId:${soundId}`);
      }
    }
    rtcEngine.registerEventHandler(EventHandler);

    // Playing sound files
    rtcEngine.playEffect(
      soundId: 0, // Setting the Sound ID
      filePath: 'your file path', // Setting the sound file path
      loopCount: 1, // Sets the number of times the sound effect is looped. 1 means looped once.
      pitch: 1.0, // Sets the pitch of the sound effect. 1.0 indicates the original pitch.
      pan: 0, // Sets the spatial position of the sound effect. 0.0 means the sound effect appears directly in front
      gain: 100, // Sets the sound volume. 100 indicates the original volume.
      publish: false, // Sets whether or not to publish the sound to the remote end
      startPos: 0, // Sets the playback position of the sound effect file. 0 means playback starts from the 0th ms of the sound effect file.
    );
    ```

    ### Incorporate audio mixing [#incorporate-audio-mixing-5]

    Call the `startAudioMixing` method to play a music file. When the music mixing state changes after a successful call to this method, the SDK triggers the `onAudioMixingStateChanged` callback to report the changed music file playback status and the reason for the change.

    Refer to the following code example:

    ```typescript
    // Register the music file's playback state has changed callback
    const EventHandler = {
      onAudioMixingStateChanged: (state, reason) => {
        console.log(`state:${state}, reason:${reason}`);
      }
    }
    rtcEngine.registerEventHandler(EventHandler);

    // Playing Music Files
    rtcEngine.startAudioMixing(
      filePath: 'your file path', // Setting the music file path
      loopback: false, // Sets whether music files are only played locally. false Indicates that locally played music files are published to the remote end, and both local and remote users can hear the music
      cycle: -1, // Sets the number of times the music file is played. -1 means infinite loop playback
      startPos: 0, // Sets the playback position of the music file. 0 means playback starts from the 0th ms of the sound file.
    );
    ```

    <CalloutContainer type="warning">
      <CalloutDescription>
        If you play a short sound effect file using `startAudioMixing`, or a long music file using `playEffect`, the playback may fail.
      </CalloutDescription>
    </CalloutContainer>

    ## Reference [#reference-6]

    This section contains content that completes the information on this page, or points you to documentation that explains other aspects to this product.

    ### API reference [#api-reference-6]

    * [`playEffect`](https://api-ref.agora.io/en/video-sdk/react-native/4.x/API/class_irtcengine.html#api_irtcengine_playeffect3)

    * [`onAudioEffectFinished`](https://api-ref.agora.io/en/video-sdk/react-native/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onaudioeffectfinished)

    * [`startAudioMixing`](https://api-ref.agora.io/en/video-sdk/react-native/4.x/API/class_irtcengine.html#api_irtcengine_startaudiomixing2)

    * [`onAudioMixingStateChanged`](https://api-ref.agora.io/en/video-sdk/react-native/4.x/API/class_irtcengineeventhandler.html#callback_irtcengineeventhandler_onaudiomixingstatechanged)

    
  
      
  
