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

feedUint8FromStream method

Future<int> feedUint8FromStream(
  1. Uint8List buffer
)

Implementation

Future<int> feedUint8FromStream(Uint8List 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.feed(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