Exoplayer: Pause/Resume download with HlsDownloader or DashDownloader

Created on 27 Feb 2018  Â·  6Comments  Â·  Source: google/ExoPlayer

Hi, I'm using exoplayer2.source.hls.offline.HlsDownloader and exoplayer2.source.dash.offline.DashDownloader to download videos that will be played offline later. I do not need an instance of Exoplayer at this time, just Downloader classes.
Are there ways to pause and resume the download?

A simple code to start download (working fine):

 val tempFolder = Util.createTempDirectory(context, "tempFolder");
 val cache = SimpleCache(tempFolder, NoOpCacheEvictor())
 val dataSourceFactory = CacheDataSourceFactory(context, 100 * 1024 * 1024, 5 * 1024 * 1024)

 val hlsDownloader = HlsDownloader(Uri.parse(videoUrl), DownloaderConstructorHelper(cache, dataSourceFactory))

 hlsDownloader.download(object: Downloader.ProgressListener {
    override fun onDownloadProgress(downloader: Downloader?, downloadPercentage: Float, downloadedBytes: Long) {
       ...
    }
  })

I've also tried the exoplayer2.upstream.CacheUtil class, but it also has no way to pause/resume downloads.
Maybe another class should be used to download videos? vov
thanks.

question

Most helpful comment

It's recommended to use recently released DownloadManager and DownloadService instead of Downloaders directly. DownloadManager has stopDownloads and startDownloads methods.

For Downloaders: You can interrupt the thread which the downloader or CacheUtil method is running:
thread.interrupt();
then the method will throw an InterruptedException. Next time you call the same method, it will continue from where it left.

All 6 comments

It's recommended to use recently released DownloadManager and DownloadService instead of Downloaders directly. DownloadManager has stopDownloads and startDownloads methods.

For Downloaders: You can interrupt the thread which the downloader or CacheUtil method is running:
thread.interrupt();
then the method will throw an InterruptedException. Next time you call the same method, it will continue from where it left.

@pmunizferreira can you please tell me how you successfully download hls videos my mobile got hanged when onProgress called. here is my email address please contact
[email protected]

@erdemguven i am stuck at hls downloading your blog is not enough kindly tell me proper way for download video in mobile storage any working code example would be grate full but dont give me a link for demo app its too complicated

@Waleedasim sorry there isn't a simple hls download example currently. I'll write another post for downloading adaptive streams soon.

Kindly do it as soon as possible really appreciate your efforts

On Tue, 15 May 2018 6:12 pm Erdem Guven, notifications@github.com wrote:

@Waleedasim https://github.com/Waleedasim sorry there isn't a simple
hls download example currently. I'll write another post for downloading
adaptive streams soon.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/google/ExoPlayer/issues/3907#issuecomment-389160984,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AlTuTfIJiUIUdpWqRVSGU8-tmmkfKOrNks5tytQhgaJpZM4SUQxF
.

Thank you for response :)

On Tue, 15 May 2018 6:17 pm Waleed Asim, waleedasim08@gmail.com wrote:

Kindly do it as soon as possible really appreciate your efforts

On Tue, 15 May 2018 6:12 pm Erdem Guven, notifications@github.com wrote:

@Waleedasim https://github.com/Waleedasim sorry there isn't a simple
hls download example currently. I'll write another post for downloading
adaptive streams soon.

—
You are receiving this because you were mentioned.
Reply to this email directly, view it on GitHub
https://github.com/google/ExoPlayer/issues/3907#issuecomment-389160984,
or mute the thread
https://github.com/notifications/unsubscribe-auth/AlTuTfIJiUIUdpWqRVSGU8-tmmkfKOrNks5tytQhgaJpZM4SUQxF
.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AndrewJack picture AndrewJack  Â·  3Comments

kambizira picture kambizira  Â·  3Comments

R00We picture R00We  Â·  3Comments

orcunkobal picture orcunkobal  Â·  3Comments

petitTrung picture petitTrung  Â·  3Comments