spotube/lib/services/download_manager/download_task.dart
Kingkor Roy Tirtho 22a49e56a2
refactor: use tcp server based track matcher (#1386)
* refactor: remove SourcedTrack based audio player and utilize mediakit playback system

* feat: implement local (loopback) server to resolve stream source and leverage the media_kit playback API

* feat: add source change support and re-add prefetching tracks

* fix: assign lastId when track fetch completes regardless of error

* chore: remove print statements

* fix: remote queue not working

* fix: increase mpv network timeout to reduce auto-skipping

* fix: do not pre-fetch local tracks

* fix(proxy-playlist): reset collections on load

* chore: fix lint warnings

* fix(mobile): player overlay should not be visible when the player is not playing

* chore: fix typo in turkish translation

* cd: checkout PR branch

* cd: upgrade flutter version

* chore: fix lint errors
2024-04-11 17:56:41 +06:00

36 lines
925 B
Dart

import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:spotube/services/download_manager/download_request.dart';
import 'package:spotube/services/download_manager/download_status.dart';
class DownloadTask {
final DownloadRequest request;
ValueNotifier<DownloadStatus> status = ValueNotifier(DownloadStatus.queued);
ValueNotifier<double> progress = ValueNotifier(0);
DownloadTask(
this.request,
);
Future<DownloadStatus> whenDownloadComplete(
{Duration timeout = const Duration(hours: 2)}) async {
var completer = Completer<DownloadStatus>();
if (status.value.isCompleted) {
completer.complete(status.value);
}
void listener() {
if (status.value.isCompleted) {
completer.complete(status.value);
status.removeListener(listener);
}
}
status.addListener(listener);
return completer.future.timeout(timeout);
}
}