Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How do you pause and resume download? #200

Open
JamLarana opened this issue Apr 10, 2022 · 2 comments
Open

How do you pause and resume download? #200

JamLarana opened this issue Apr 10, 2022 · 2 comments

Comments

@JamLarana
Copy link

JamLarana commented Apr 10, 2022

In situations where internet connection is lost, or when a user would like to pause downloading and resume downloading later. How do you handle that?

@Hexer10
Copy link
Owner

Hexer10 commented Apr 13, 2022

If it is fine for you to pause a download while still have the stream subscription open you can use the stream pause and resume methods:

  final _sub = yt.videos.streams.get(stream).listen((data) {
    // Process the video content.
  }, onDone: () {
    print('Download finished');
  });


  await Future.delayed(const Duration(seconds: 2));
  _sub.pause();
  print('Download paused for 5 seconds...');
  await Future.delayed(const Duration(seconds: 5));
  print('Resuming download');
  _sub.resume();

if you want to pause a download and resume it for example after an application restart, then that's not currently possible.

@MSOB7YY
Copy link

MSOB7YY commented Aug 11, 2023

you can achieve that by using range in http header
by pausing download, you are closing the request, and resuming means opening a new get request but with range header
so what you should do for resuming is:

  1. get the file size File(path).statsSync().size
  2. create a new client with the header
    ( headers.addAll({"range": "byte=fileSize-});
    read more about range header for more control

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants