Skip to main content Link Menu Expand (external link) Document Search Copy Copied
feedF32FromStream method - FlutterSoundPlayer class - player library - Dart API
menu
feedF32FromStream

feedF32FromStream method

Future<int> feedF32FromStream(
  1. List<Float32List> buffer
)

Feed a Float32 stream not interleaved when a flow control is wanted


Please look to this small guide if you need help.

Parameters

  • buffer: is a List of Float32List containing the audio data that you want to play. The List length must be equal to the number of channels. All the Float32List length MUST be same and contain your data.

Return

Returns a Future that you MUST await if you really need a flow control. This future is declared completed when the data has been played, or at least when they had be given to the lower layer of the software. Note: don't use the int returned. It is just for legacy reason and must not be used.

Example

await myPlayer.startPlayerFromStream
(
    codec: Codec.pcmFloat32
    numChannels: 2
    sampleRate: 48100
    interleaved: false,
);

await myPlayer.feedF32FromStream(myData);

See also


Implementation

Future<int> feedF32FromStream(List<Float32List> buffer) async {
  await _waitOpen();
  if (_isInited != Initialized.fullyInitialized) {
    throw Exception('Player is not open');
  }
  if (isStopped) {
    return 0;
  }
  _needSomeFoodCompleter =
      Completer<int>(); // Not completed until the device accept new data
  try {
    var ln = await (FlutterSoundPlayerPlatform.instance.feedFloat32(
      this,
      data: buffer,
    ));
    assert(ln >= 0); // feedFromStream() is not happy if < 0
    if (ln != 0) {
      // If the device accepted some data, then no need to wait
      // It is the tau_core responsability to send a "needSomeFood" then it is again available for new data
      _needSomeFoodCompleter = null;
      return (ln);
    } else {
      //logger.i("The device has enough data");
    }
  } on Exception {
    _needSomeFoodCompleter = null;
    if (isStopped) {
      return 0;
    }
    rethrow;
  }

  if (_needSomeFoodCompleter != null) {
    return _needSomeFoodCompleter!.future;
  }
  return 0;
}
flutter_sound 9.25.3