Fix the error of incomplete data loading on the Android emulator.

This commit is contained in:
vi-k 2021-09-03 16:12:30 +10:00
parent bba4ba97b6
commit f75767ea2a
1 changed files with 6 additions and 6 deletions

View File

@ -117,21 +117,21 @@ class YoutubeHttpClient extends http.BaseClient {
int errorCount = 0}) async* {
var url = streamInfo.url;
var bytesCount = start;
for (var i = start; i < streamInfo.size.totalBytes; i += 9898989) {
while (bytesCount != streamInfo.size.totalBytes) {
try {
final response = await retry(() {
final request = http.Request('get', url);
request.headers['range'] = 'bytes=$i-${i + 9898989 - 1}';
request.headers['range'] = 'bytes=$bytesCount-${bytesCount + 9898989 - 1}';
return send(request);
});
if (validate) {
_validateResponse(response, response.statusCode);
}
final stream = StreamController<List<int>>();
response.stream.listen((data) {
bytesCount += data.length;
stream.add(data);
}, onError: (_) => null, onDone: stream.close, cancelOnError: false);
response.stream.listen((data) {
bytesCount += data.length;
stream.add(data);
}, onError: (_) => null, onDone: stream.close, cancelOnError: false);
errorCount = 0;
yield* stream.stream;
} on Exception {