addData method
Adds data to the buffer and processes it with controlled timing.
Implementation
void addData(String base64String) {
final currentTime = DateTime.now().millisecondsSinceEpoch;
// Append incoming data to the buffer
_dataBuffer += base64String;
final elapsedTime = currentTime - _lastSentTime;
// If it's been at least _interval milliseconds or no new data is received within the interval
if (elapsedTime >= interval.inMilliseconds) {
_sendDataToPlayer();
} else {
_timer?.cancel();
// Set a timer to send data if no further data arrives within the remaining interval
_timer = Timer(
Duration(
milliseconds: interval.inMilliseconds - elapsedTime,
),
_sendDataToPlayer);
}
}