Package com.castlabs.sdk.downloader
Class DownloadServiceBinder
java.lang.Object
android.os.Binder
com.castlabs.sdk.downloader.DownloadServiceBinder
- All Implemented Interfaces:
- IBinder
The binder providing access to 
DownloadService.
 
 Bind to DownloadService as follows:
 
 DownloadServiceBinder downloadServiceBinder;
 ServiceConnection downloadServiceConnection = new ServiceConnection() {
        public void onServiceConnected(ComponentName componentName, IBinder iBinder) {
                downloadServiceBinder = (DownloadServiceBinder) iBinder;
        }
        public void onServiceDisconnected(ComponentName componentName) {
                downloadServiceBinder = null;
        }
 }
 String downloadId = "ID";
 File moviesFolder = getExternalFilesDir(Environment.DIRECTORY_MOVIES);
 File target = new File(moviesFolder, "Downloads/" + downloadId);
 Bundle bundle = new Bundle();
 bundle.putString(SdkConsts.INTENT_URL, "MANIFEST_URL");
 bundle.putString(SdkConsts.INTENT_DOWNLOAD_ID, downloadId);
 bundle.putString(SdkConsts.INTENT_DOWNLOAD_FOLDER, target.getAbsolutePath());
 downloadServiceBinder.prepareDownload(context, bundle, new Downloader.ModelReadyCallback() {
        public void onError(@NonNull Exception e) {
                Log.e(TAG, "Error while preparing download: " + e.getMessage(), e);
        }
        public void onModelAvailable(@NonNull Download download) {
                // initiate selection here of video quality, audio and subtitle tracks
                // either automatically or manually
        }
 });
 - Since:
- 3.2.0
- 
Nested Class SummaryNested classes/interfaces inherited from interface android.os.IBinderIBinder.DeathRecipient
- 
Field SummaryFieldsModifier and TypeFieldDescriptionstatic booleanThis flag indicates whether to allowdownloadsto be downloaded into system paths which are not part of the scoped storage.static booleanFields inherited from interface android.os.IBinderDUMP_TRANSACTION, FIRST_CALL_TRANSACTION, FLAG_ONEWAY, INTERFACE_TRANSACTION, LAST_CALL_TRANSACTION, LIKE_TRANSACTION, PING_TRANSACTION, TWEET_TRANSACTION
- 
Method SummaryModifier and TypeMethodDescriptionvoidcreateDownload(Download download, boolean startDownload) Stores the download internally and if the startDownload is set then adds the download into the download queue.voiddeleteDownload(String downloadId) Deletes download identified by download Id.static voidfetchLicense(Download download, DrmConfiguration drmConfiguration, DrmLicenseLoader.Callback callback) Fetches the appropriate license for the given Download.findDownloadById(String downloadId) Finds download by download IdReturns a list of all downloads that are currently available in the storagevoidpauseDownload(String downloadId) Pauses download identified by download Id.voidprepareDownload(Context context, Bundle bundle, Downloader.ModelReadyCallback callback) Creates the download model by downloading and parsing the manifest.static voidremoveLicense(Download download, DrmConfiguration drmConfiguration, DrmLicenseLoader.Callback callback) Removes the appropriate license for the given Download.voidresumeDownload(String downloadId) Resumes download identified by download Id.voidStarts the downloader service and resumes downloading queued downloads.voidStops theDownloadServiceif it's running.voidupdateDownloadPath(String downloadId, String newPath) Updates the internal download path.Methods inherited from class android.os.BinderattachInterface, clearCallingIdentity, clearCallingWorkSource, dump, dumpAsync, flushPendingCommands, getCallingPid, getCallingUid, getCallingUidOrThrow, getCallingUserHandle, getCallingWorkSourceUid, getInterfaceDescriptor, isBinderAlive, joinThreadPool, linkToDeath, pingBinder, queryLocalInterface, restoreCallingIdentity, restoreCallingWorkSource, setCallingWorkSourceUid, transact, unlinkToDeath
- 
Field Details- 
allowNonScopedStorageDownloadpublic static boolean allowNonScopedStorageDownloadThis flag indicates whether to allowdownloadsto be downloaded into system paths which are not part of the scoped storage. This flag is false by default.
- 
autoStopServicepublic static boolean autoStopServiceThis flag indicates whether to stop theServiceonce there are no pendingdownloads. You may want to disable this flag in case your workflow contemplates starting or resuming Downloads whenever the app is in background, or whenever the App is in a state which is not allowed by the system topromote the service to foreground. If disabled, you must take responsibility for stopping the service once it's not needed by your Application anymore. The recommended approach is to listen for theMessageHandler.ACTION_DOWNLOAD_NO_PENDINGbroadcast event. SeestopService(). true by default.
 
- 
- 
Method Details- 
getDownloadsReturns a list of all downloads that are currently available in the storage- Returns:
- The list of all available downloads
- Throws:
- IOException- In case an error occurs while reading the download list
 
- 
findDownloadByIdFinds download by download Id- Parameters:
- downloadId- The download Id
- Returns:
- The found download or null otherwise
 
- 
deleteDownloadDeletes download identified by download Id. This is the asynchronous call and after the download is successfully deleted theMessageHandler.ACTION_DOWNLOAD_DELETEDis sent orMessageHandler.ACTION_DOWNLOAD_ERRORin case of error. In case the download is currently loading then it is deleted and the next scheduled download is started.- Parameters:
- downloadId- The download Id
 
- 
updateDownloadPathUpdates the internal download path. Note that data migration (Media content) is *NOT* moved by this method. It *won't* migrate the contents of the Download to the specified path. This is to be called after data migration is performed manually. For more information check out the "Scoped Storage" section inside the Downloader in the SDK manual.- Parameters:
- downloadId- The Download Id
- newPath- The new path
 
- 
fetchLicensepublic static void fetchLicense(@NonNull Download download, @Nullable DrmConfiguration drmConfiguration, @NonNull DrmLicenseLoader.Callback callback) Fetches the appropriate license for the given Download. Note that this a static method, since it's just a convenience method and does not require an activeDownloadService.- Parameters:
- download- the Download for which to fetch the license.
- drmConfiguration-- DrmConfigurationused to fetch the license. If null, the Download's configuration will be used instead
- callback- Callback to be invoked when the license is retrieved or an error occurs
 
- 
removeLicensepublic static void removeLicense(@NonNull Download download, @Nullable DrmConfiguration drmConfiguration, @NonNull DrmLicenseLoader.Callback callback) Removes the appropriate license for the given Download. Note that this a static method, since it's just a convenience method and does not require an activeDownloadService.- Parameters:
- download- the Download for which to remove the license.
- drmConfiguration-- DrmConfigurationused to remove the license. If null, the Download's configuration will be used instead
- callback- Callback to be invoked when the license is removed or an error occurs
 
- 
resumeDownloadResumes download identified by download Id. This is the asynchronous call and after the download is successfully resumed theMessageHandler.ACTION_DOWNLOAD_STARTEDis broadcasted orMessageHandler.ACTION_DOWNLOAD_ERRORin case of error. In case the device storage is low, the download is not resumed and theMessageHandler.ACTION_DOWNLOAD_STORAGE_LOWis broadcasted- Parameters:
- downloadId- The download Id
 
- 
pauseDownloadPauses download identified by download Id. This is the asynchronous call and after the download is successfully paused theMessageHandler.ACTION_DOWNLOAD_STOPPEDis broadcasted orMessageHandler.ACTION_DOWNLOAD_ERRORin case of error. In case the device storage is enough the next scheduled download is started.- Parameters:
- downloadId- The download Id
 
- 
createDownloadStores the download internally and if the startDownload is set then adds the download into the download queue. This is the asynchronous call and after the download is stored, theMessageHandler.ACTION_DOWNLOAD_CREATEDis broadcasted. If the startDownload is set then after successful adding of the download into the download queue theMessageHandler.ACTION_DOWNLOAD_STARTEDis sent orMessageHandler.ACTION_DOWNLOAD_ERRORin case of error. In case the device storage is low, theMessageHandler.ACTION_DOWNLOAD_STORAGE_LOWis broadcasted instead.- Parameters:
- download- The download
- startDownload- The flag whether to start the download upon creation.
- Throws:
- IOException- In case an error occurs while reading the download list
 
- 
resumeQueuedDownloadspublic void resumeQueuedDownloads()Starts the downloader service and resumes downloading queued downloads. Use this method primarily when you use theDownloaderPlugin.STORAGE_LOW_MODE_QUEUEDstorage mode and you want to restart pending downloads.
- 
prepareDownloadpublic void prepareDownload(@NonNull Context context, @NonNull Bundle bundle, @Nullable Downloader.ModelReadyCallback callback) Creates the download model by downloading and parsing the manifest. The caller callback is invoked upon completion. This method takes aBundleand extracts the information needed for the download model. The following bundle keys will be checked:- SdkConsts.INTENT_URLexpects a String (mandatory)
- SdkConsts.INTENT_DOWNLOAD_IDexpects a String (mandatory)
- SdkConsts.INTENT_DOWNLOAD_FOLDERexpects a String (mandatory)
- SdkConsts.INTENT_DRM_CONFIGURATIONexpects a- DrmConfiguration(optional)
- SdkConsts.INTENT_CONTENT_TYPEexpects a- Integer(default:- SdkConsts.CONTENT_TYPE_UNKNOWNto auto-detect). Allowed values are one of- SdkConsts.CONTENT_TYPE_UNKNOWN,- SdkConsts.CONTENT_TYPE_DASH,- SdkConsts.CONTENT_TYPE_SMOOTHSTREAMING, or- SdkConsts.CONTENT_TYPE_MP4
 SdkConsts.INTENT_HD_CONTENT_FILTERSdkConsts.INTENT_VIDEO_SIZE_FILTERSdkConsts.INTENT_VIDEO_CODEC_FILTERSdkConsts.INTENT_MERGE_VIDEO_TRACKS- Parameters:
- context- The context
- bundle- The bundle
- callback- The caller callback or null
 
- 
stopServicepublic void stopService()Stops theDownloadServiceif it's running. Also pauses any ongoing Downloads. There's usually no need to call this method, unless you're settingautoStopServiceto false.
 
-