pushExternalAudioFrame method

Future<int?> pushExternalAudioFrame(
  1. AudioFrame audioFrame
)

@detail api @brief Push PCM audio frame data for mixing. @param audioFrame See AudioFrame{@link #AudioFrame}.
- The audio sampling format must be S16. The data format within the audio buffer must be PCM, and its capacity size should be audioFrame.samples × audioFrame.channel × 2. - A specific sample rate and the number of channels must be specified. Setting them to automatic is not supported. @return - 0: Success. - < 0: Failed. @note - Before calling this method, the raw audio data mixing must be enabled through openWithCustomSource{@link #IMediaPlayer#openWithCustomSource}. - Suggestions: Before pushing data for the first time, please cache a certain amount of data (like 200 ms) on the application side, and then push it at once. Schedule subsequent push operation every 10 ms with audio data of 10 ms. - To pause the playback, just pause the push.

Implementation

Future<int?> pushExternalAudioFrame(AudioFrame audioFrame) async {
  $a() => ($instance as $p_a.IMediaPlayer)
      .pushExternalAudioFrame(unpackObject<$p_a.AudioFrame>(audioFrame));
  $i() => ($instance as $p_i.ByteRTCMediaPlayer).pushExternalAudioFrame(
      unpackObject<$p_i.ByteRTCAudioFrame>(audioFrame));

  if (Platform.isAndroid) {
    return $a();
  } else if (Platform.isIOS) {
    return $i();
  } else {
    throw UnsupportedError(
        'Not Support Platform ${Platform.operatingSystem}');
  }
}