You need to use a CacheDataSource (or CacheDataSourceFactory) with the Cache you used for downloading while creating your MediaSource. Downloaded content is split into multiple small cache files so it isn’t possible to play content directly from the files. Playing the downloaded content is basically reading data from cache instead of network. Details will be covered in a separate post. Additionally you need to specify which representations you want to download. There is also an optional data parameter which can be used to store application specific information.Ĭreating DownloadActions for DASH, HLS and SmoothStreaming is similar. You need to specify the uri of the content and whether you want to download it, or remove what has already been downloaded. For example, to download a progressive stream, you need to create a ProgressiveDownloadAction: ProgressiveDownloadAction( Uri uri, // Uri of the data to be downloaded boolean removeAction, // If true, removes downloaded data String data, // Optional custom data for this action String customCacheKey) // Optional custom cache key You need to use the right subclass of DownloadAction for the stream you want to download. startWithAction( Context context, Class clazz, // your subclass DownloadAction downloadAction, boolean foreground) To do a request you can call: DownloadService. The service is started with the first download request. There is another constructor of DownloadManager by which you can set the maximum number of simultaneous downloads. You need to pass in the Deserializers associated with the stream types you want to download. For example DashDownloadAction.DESERIALIZER for DASH content. There is one Deserializer implementation for each stream type. Deserializers are used to load actions from actionFile.SimpleCache deletes any file it doesn’t know. DON’T give a path in the folder you used for SimpleCache to store downloaded content. So when the app restarts these actions can be continued. actionFile is the file where DownloadActions are saved.DownloaderConstructorHelper holds necessary parameters for constructing Downloaders.There are three parameters you need to provide for the simplest constructor of DownloadManager: DownloadManager( // A helper class for creating Downloader s DownloaderConstructorHelper constructorHelper, // File to save active actions File actionFile, // Used to deserialize DownloadAction s Deserializer. You can use buildProgressNotification method in DownloadNotificationUtil to create a notification in default style. getForegroundNotification() returns a notification to be displayed when the service running in the foreground. ![]() See for details: PlatformScheduler, JobDispatcherScheduler and Requirements. ![]() getScheduler() and getRequirements() return a optional Scheduler and requirements that control when downloads should be allowed to proceed.getDownloadManager() returns the DownloadManager to be used.Simplified interaction graph of the classes Creating a DownloadServiceĭownloadService is an abstract class to use it you need to subclass it and implement its abstract methods: Note, although the Downloaders can be used standalone, it’s recommended to use DownloadService and DownloadManager for full functionality. ![]() For example, it can be configured to start downloads when there is an unmetered network or while the device is charging, even while the app isn’t running. Scheduler is used to start and stop DownloadService depending on whether specified requirements are met.DownloadService executes downloads as a Android service so they can continue even if the app exits.There is one subclass for each stream type. It contains necessary parameters to initiate the download. DownloadAction is used to request downloading media or removing an already downloaded media by DownloadManager.Downloads can be done in parallel or sequentially. DownloadManager manages multiple downloads and persists download tasks.One Downloader downloads only one stream. There are subclasses for DASH, HLS, SmoothStreaming and also progressive streams. Downloader downloads one certain type of stream.HttpDataSource is used to read HTTP resources. DataSource is used to read streams of data.When used for downloading it is configured without a disk space limit and not to delete anything. Normally, for caching purposes it’s configured to use a limited amount of disk space and delete least recently used data. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |