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

feedInt16FromStream method

Future<int> feedInt16FromStream(
  1. List<Int16List> buffer
)

Implementation

Future<int> feedInt16FromStream(List<Int16List> 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.feedInt16(
      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.24.0