startAudioMixing abstract method

Future<void> startAudioMixing({
  1. required String filePath,
  2. required bool loopback,
  3. required int cycle,
  4. int startPos = 0,
})

Starts playing a music file.

See Supported audio file formats for the audio formats supported by this method. If the local music file does not exist, the file format is not supported, or the online music file URL cannot be accessed, the SDK reports audioMixingReasonCanNotOpen. Using this method to play short sound effects may cause playback failure. To play sound effects, use playEffect instead. If you need to call this method multiple times, make sure the interval between calls is more than 500 ms. When calling this method on Android, note the following: Make sure to use a device with Android 4.2 or above and API level no lower than 16. If playing online music files, avoid using redirect URLs. Redirect URLs may not work on some devices. If calling this method on an emulator, make sure the music file is under the /sdcard/ directory and in MP3 format.

  • filePath File path: Android: File path, must include the file name and extension. Supports URL of online files, URI of local files, absolute paths, or paths starting with /assets/. Accessing local files via absolute path may cause permission issues. It is recommended to use URI. For example: content://com.android.providers.media.documents/document/audio%3A14441. Windows: Absolute path or URL to the audio file, must include the file name and extension. For example: C:\music\audio.mp4. iOS or macOS: Absolute path or URL to the audio file, must include the file name and extension. For example: /var/mobile/Containers/Data/audio.mp4.
  • loopback Whether to play the music file locally only: true : Play the music file locally only. Only the local user can hear the music. false : Publish the locally played music file to remote users. Both local and remote users can hear the music.
  • cycle Number of times to play the music file.

0: Number of times to play. For example, 1 means play once. -1: Play in an infinite loop.

  • startPos The playback position of the music file, in milliseconds.

Returns When the method call succeeds, there is no return value; when fails, the AgoraRtcException exception is thrown. You need to catch the exception and handle it accordingly. See Error Codes for details and resolution suggestions.

Implementation

Future<void> startAudioMixing(
    {required String filePath,
    required bool loopback,
    required int cycle,
    int startPos = 0});