|
@@ -36,14 +36,14 @@ abstract class VidDataChannel {
|
|
|
|
|
|
|
|
|
|
|
|
-
|
|
|
- Future<bool> load([int timeoute = 10 * 1000]) async {
|
|
|
+
|
|
|
+ Future<bool> load([int timeout = 5 * 1000]) async {
|
|
|
if (_initialized) return true;
|
|
|
|
|
|
try {
|
|
|
final completer = Completer<bool>();
|
|
|
final timer = Timer(
|
|
|
- Duration(milliseconds: timeoute),
|
|
|
+ Duration(milliseconds: timeout),
|
|
|
() {
|
|
|
if (!completer.isCompleted) {
|
|
|
completer.complete(_initialized);
|
|
@@ -53,7 +53,7 @@ abstract class VidDataChannel {
|
|
|
}
|
|
|
},
|
|
|
);
|
|
|
- _innerLoad().then((value) {
|
|
|
+ _innerLoad(timeout).then((value) {
|
|
|
_initialized = true;
|
|
|
if (timer.isActive) {
|
|
|
timer.cancel();
|
|
@@ -73,9 +73,10 @@ abstract class VidDataChannel {
|
|
|
downloadProgressChanged.emit(this, info);
|
|
|
}
|
|
|
|
|
|
- Future<bool> _innerLoad() async {
|
|
|
+ Future<bool> _innerLoad(int timeout) async {
|
|
|
try {
|
|
|
source = await buildSource();
|
|
|
+ source!.setReadHeaderTimeout(timeout + 50);
|
|
|
await source!.initialize();
|
|
|
return true;
|
|
|
} catch (e) {
|
|
@@ -91,10 +92,21 @@ abstract class VidDataChannel {
|
|
|
|
|
|
|
|
|
|
|
|
- Future<VidUsImage> getImage(int index) async {
|
|
|
+
|
|
|
+
|
|
|
+ Future<VidUsImage> getImage(int index, [int timeout = 500]) async {
|
|
|
+ source!.setReadImageTimeout(timeout);
|
|
|
return source!.getImage(index);
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ void close() {
|
|
|
+ _initialized = false;
|
|
|
+ try {
|
|
|
+ source?.close();
|
|
|
+ } catch (e) {}
|
|
|
+ }
|
|
|
+
|
|
|
@protected
|
|
|
Future<AsyncVidImageDataBase> buildSource();
|
|
|
}
|