Class OfflineDownloadFactory
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidTears down the offline download stack - theDownloadManager, the download cache and its database.static OfflineDownloadManagergetOfflineDownloadManager(android.content.Context context) Returns the DrmDownloadManager responsible for managing a specific piece of media.static OfflineDrmCallbackProviderThe provider registered bysetOfflineDrmCallbackProvider(com.jwplayer.pub.api.offline.OfflineDrmCallbackProvider), ornull.static voidRegisters the host's source ofMediaDrmCallbacks for offline DRM, for the life of the process.
-
Method Details
-
setOfflineDrmCallbackProvider
Registers the host's source ofMediaDrmCallbacks for offline DRM, for the life of the process.Call this once, from
Application.onCreate(). The SDK asks the provider whenever it needs a callback for a download's offline licence - both when acquiring one and when releasing it after a removal - so a host with a custom-auth licence server can delete a download from any screen, and in any later run of the app, and still have the release authenticated.Nothing is persisted. That is the point: the callback is
Parcelable, but the data stored with a download is JSON and marshalling aParcelableinto durable storage is unsupported - the format is not stable across releases, so a stored callback could fail to unmarshal after an upgrade. Re-registering on every launch is what makes this survive a restart.A callback attached to the
PlaylistItempassed toOfflineDownloadManager.prepareMediaDownload(android.content.Context, com.jwplayer.pub.api.media.playlists.PlaylistItem)still takes precedence for that item; the provider is the fallback.Do not capture an Activity in the provider or in the callbacks it returns - see
OfflineDrmCallbackProvider.Survives
destroyAll()on purpose, and may be called at any time. Passnullto unregister. -
getOfflineDrmCallbackProvider
The provider registered bysetOfflineDrmCallbackProvider(com.jwplayer.pub.api.offline.OfflineDrmCallbackProvider), ornull. -
getOfflineDownloadManager
Returns the DrmDownloadManager responsible for managing a specific piece of media. Will return null if the mediaId is null or empty- Parameters:
context- The application context
-
destroyAll
public static void destroyAll()Tears down the offline download stack - theDownloadManager, the download cache and its database. Process-scoped, not Activity-scoped: these resources are shared by the download foreground service and by offline playback, so this must not be tied to one screen'sonDestroy(). Detach yourMediaDownloadResultListenerthere instead; the stack itself is safe to leave alive for the life of the process.Refuses to tear down while a download is actively writing - downloading, restarting or being removed - because releasing the cache and closing the database under one truncates it while its index row still says otherwise. In that case this call logs and returns without releasing anything, and may be retried once those downloads have finished or been removed.
A paused download does not block teardown, and neither does one queued waiting on a requirement such as a network: neither holds an open writer, and both survive teardown intact on disk. This matters because pausing is the one thing a host can do to make teardown possible without discarding work - if a pause blocked it, a host that pauses and retries would never tear down at all.
After a successful teardown the stack can be built again:
getOfflineDownloadManager(Context)returns a working manager, and downloads started through it reach the download service normally. This is only true because teardown also drops the player library's process-wide cache of download-manager helpers - see the note in the implementation. Without that, the service would keep serving the released manager and every later download would be silently dropped.Does not unregister the provider set by
setOfflineDrmCallbackProvider(OfflineDrmCallbackProvider). That registration is process-scoped by design, and the case it exists for is a removal made after the stack has been torn down.Must be called from the thread the offline stack was created on (normally the main thread). Null-safe and idempotent: calling it twice, or before anything was built, is harmless.
-