THEOplayer / samples-ios-sdk

13 stars 8 forks source link

[Offline-Playback] Is it possible to resume cashingTask after app relaunch from previous download progress? #3

Closed Igorsnaki closed 4 years ago

Igorsnaki commented 4 years ago

Dear developers,

Thanks for sample codes. I am working on download feature using THEOPlayer.

I downloaded 'Offine-Playback' sample and noticed, that :

Actual result: current progress doesn't save.

I tried to do the following in sample code : OfflineViewViewModel init()

init() {
        for stream in streams {
            let offlineTableViewCellViewModel = OfflineTableViewCellViewModel(stream: stream)
            /* Check status of all existing caching tasks
                If task status is done assign the task to the view model object
                Remove the task by default as terminating app during caching for example will resulting an error task.
             */
            for task in THEOplayer.cache.tasks {
                for source in task.source.sources {
                    if source.src == URL(string: stream.url) {
                        os_log("Found caching task for URL: %@, task status: %@", stream.url, task.status.rawValue)
                        switch task.status {
                        case .done:
                            offlineTableViewCellViewModel.cachingTask = task
                        case .idle:
                            offlineTableViewCellViewModel.cachingTask = task
                            offlineTableViewCellViewModel.resumeCaching()
                        default:
                            // Remove caching task
                            task.remove()
                            if let _ = source.drm {
                                // Remove DRM renew record
                                UserDefaults.standard.removeObject(forKey: stream.url)
                            }
                        }
                    }
                }
            }

            cellViewModels.append(offlineTableViewCellViewModel)
        }
    }

I added this code :

                        case .idle:
                            offlineTableViewCellViewModel.cachingTask = task
                            offlineTableViewCellViewModel.resumeCaching()

I expect that IF user previously download 40% of file and after relaunch if he try to resume cachingTask - the progress will start from 40% , but it starts from begining.

All the properties in caching task are 0.0 :

/// The amount of content that has already been cached.
var secondsCached: Double { get }

/// The percentage of content (between 0 and 1) that has already been cached.
var percentageCached: Double { get }

/// The amount of bytes that has already been cached.
var bytesCached: UInt { get }

My question is :

Is it possible to keep cached progress / bytes between app launches? How?

Thank you in advance

savdeepgandhi13 commented 4 years ago

Hello @Igorsnaki

As discussed, this is not possible at the moment through our existing caching API. This is a known limitation and THEOplayer will be working on this in upcoming future to obtain the same usecase.

Thanks