youtubedl-android icon indicating copy to clipboard operation
youtubedl-android copied to clipboard

Background task inquiry

Open astroncc opened this issue 2 years ago • 5 comments

There is a conversion process when downloading MP3s. In the case of a video over an hour, the conversion takes too long. And when I move the app to home, it doesn't seem to work in the background. Is it possible to check?

astroncc avatar May 10 '22 10:05 astroncc

Maybe we should use WorkManager.

Edit: Checkout dvd, a video downloader app based on this library it is using WorkManager.

xibr avatar May 10 '22 10:05 xibr

Maybe we should use WorkManager.

Edit: Checkout dvd, a video downloader app based on this library it is using WorkManager.

Is it possible to convert even in the background to a work manager or foreground service?

astroncc avatar May 10 '22 18:05 astroncc

yes, with workmanager you can download a video and convert it to mp3 even if the video is more than 3 hours the download will continue in the background.

xibr avatar May 11 '22 04:05 xibr

yes, with workmanager you can download a video and convert it to mp3 even if the video is more than 3 hours the download will continue in the background.

I called work manager as below I added the request option in doWork and executed it. Is it correct to do this?

OneTimeWorkRequest mathWork = new OneTimeWorkRequest.Builder(DownloadWorker.class).build(); WorkManager.getInstance(context).enqueue(mathWork);

astroncc avatar May 11 '22 04:05 astroncc

For example


        Constraints.Builder builder = new Constraints.Builder().setRequiredNetworkType(NetworkType.CONNECTED);
 
        // Passing params
        Data.Builder data = new Data.Builder();
        data.putString("tag", tag);
        data.putString("url", url);
        data.putString("title", title);
        data.putString("format", format);
 
        OneTimeWorkRequest syncWorkRequest = new OneTimeWorkRequest.Builder(DownloadWorker.class)
                .addTag(tag)
                .setInputData(data.build())
                .setConstraints(builder.build())
                .build();
 
        WorkManager.getInstance(context).enqueueUniqueWork(tag, ExistingWorkPolicy.KEEP, syncWorkRequest);
 

Also for more information please see this https://developer.android.com/topic/libraries/architecture/workmanager/advanced/long-running

xibr avatar May 11 '22 05:05 xibr