feedInt16FromStream
feedInt16FromStream method
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;
}