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 to fetch downloaded video #23

Open
ErMapsh opened this issue May 30, 2024 · 3 comments
Open

How to fetch downloaded video #23

ErMapsh opened this issue May 30, 2024 · 3 comments

Comments

@ErMapsh
Copy link

ErMapsh commented May 30, 2024

- Using README.MD, I save videos(files) to directories.documents directory, now I have the challenge of fetching downloaded videos with metadata and play, how can I do it? @kesha-antonov

const downloadVideo = async data => {
    try {
      if (downloadState == 'DOWNLOAD') {
        const url = data.videoUrl;
        const jobId = String(data.id);
        let task = download({
          id: jobId,
          url: url,
          destination: `${directories.documents}/${jobId}.mp4`,
          metadata: data,
        })
          .begin(({expectedBytes, headers}) => {
            console.log(`Going to download ${expectedBytes} bytes!`);
            setDownloadState('DOWNLOADING');
          })
          .progress(({bytesDownloaded, bytesTotal}) => {
            console.log(`Downloaded: ${(bytesDownloaded / bytesTotal) * 100}%`);
            setDownloadState('DOWNLOADING');
          })
          .done(async ({bytesDownloaded, bytesTotal}) => {
            setDownloadState('DONE');
            console.log('Download is done!', {bytesDownloaded, bytesTotal});
            let res = await completeHandler(jobId);
            console.log('res', res);
          })
          .error(({error, errorCode}) => {
            Toast.show({
              type: ALERT_TYPE.DANGER,
              title: 'Error',
              textBody: 'Try again Later',
              button: 'close',
              closeOnOverlayTap: false,
              onPressButton: () => {
                Toast.hide();
              },
            });
            console.log('Download canceled due to error: ', {error, errorCode});
          });
      } else if (downloadState == 'DOWNLOADING' || downloadState == 'PAUSED') {
        /* open modal from bottom */
        console.log('Opening modal');
      } else if (downloadState == 'DONE') {
        /* open dialog box */
        console.log('Dialog box');
      }
    } catch (error) {
      console.log(error);
    }
  };

Need another enhancement if possible

  1. resume and pause in both platform, not able to pause in android
@ErMapsh
Copy link
Author

ErMapsh commented Jun 6, 2024

    // https://android-review.googlesource.com/c/platform/packages/providers/DownloadProvider/+/2089866
    public void pauseDownload(long downloadId) {
        // ContentValues values = new ContentValues();

        // values.put(Downloads.Impl.COLUMN_CONTROL, Downloads.Impl.CONTROL_PAUSED);
        // values.put(Downloads.Impl.COLUMN_STATUS,
        // Downloads.Impl.STATUS_PAUSED_BY_APP);

        // downloadManager.mResolver.update(ContentUris.withAppendedId(mBaseUri,
        // ids[0]), values, null, null)
    }

    public void resumeDownload(long downloadId) {
        // ContentValues values = new ContentValues();

        // values.put(Downloads.Impl.COLUMN_STATUS, Downloads.Impl.STATUS_PENDING);
        // values.put(Downloads.Impl.COLUMN_CONTROL, Downloads.Impl.CONTROL_RUN);
    } 

I'm looking to resolve this issue but I can't find the way to fix the issue, can u look out this @kesha-antonov

@kesha-antonov
Copy link
Owner

kesha-antonov commented Jun 6, 2024

Hey man
Overwhelmed with work rn
It's open source, feel free to improve code & propose PR

@ErMapsh
Copy link
Author

ErMapsh commented Jun 6, 2024

Hey man Overwhelmed with work rn It's open source, feel free to improve code & propose PR

sure, why not I will try

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

2 participants