BMPOfflineManager
Objective-C
@interface BMPOfflineManager : NSObject
Swift
class OfflineManager : NSObject
IMPORTANT: Methods from BMPOfflineManager need to be called from the main thread.
This class offers functionality to handle the whole lifecycle of protected and unprotected offline content. Do not create own instances of it, instead use [OfflineManager sharedInstance] to obtain a reference to the singleton.
Depending on the current state of the SourceConfig, which can be obtained by calling offlineStateForSourceConfig:, different methods are allowed to be called on the BMPOfflineManager. The table below shows all possible and allowed transitions between the different states. Each line describes one transition which happens immediately and synchronous. When there is a method call noted in column “Method call triggering transition”, the “Following State” is entered immediately after the method call returns.
When there is no method call noted, the “Following State” is entered when the event described in column “BMPOfflineManagerListener event” was received.
The “Following State” is always noted under the assumption that no error occurred when calling the transition method, or during processing of the current task. Errors are always reported to offlineManager:didFailWithError:. See the documentation of OfflineManagerListener for more information.
| Current State | Method call triggering transition | BMPOfflineManagerListener event | Following State |
|---|---|---|---|
| NotDownloaded | downloadSourceConfig: | - | Downloading |
| Downloading | cancelDownloadForSourceConfig: | - | Canceling |
| Downloading | suspendDownloadForSourceConfig: | offlineManagerDidSuspendDownload: | Suspended |
| Downloading | - | offlineManagerDidFinishDownload: | Downloaded |
| Downloading | - | offlineManager:didProgressTo: | Downloading |
| Downloaded | deleteOfflineDataForSourceConfig: | - | NotDownloaded |
| Suspended | resumeDownloadForSourceConfig: | offlineManager:didResumeDownloadWithProgress: | Downloading |
| Suspended | cancelDownloadForSourceConfig: | - | Canceling |
| Canceling | - | offlineManagerDidCancelDownload: | NotDownloaded |
| Downloaded | renewOfflineLicenseForSourceConfig: | offlineManagerDidRenewOfflineLicense: | Downloaded |
-
Value in megabytes for minimum system free space available before suspending active downloads. Default value is 500Mb.
Declaration
Objective-C
@property (class, nonatomic) NSUInteger minimumAvailableSpaceThreshold;Swift
class var minimumAvailableSpaceThreshold: UInt { get set } -
Indicates if the OfflineManager is initialized.
Declaration
Objective-C
@property (class, readonly) BOOL isOfflineManagerInitialized;Swift
class var isOfflineManagerInitialized: Bool { get } -
Specifies if an active WiFi connection is required for downloading media for offline playback. Default is
NO.Declaration
Objective-C
@property (nonatomic) BOOL restrictMediaDownloadsToWiFi;Swift
var restrictMediaDownloadsToWiFi: Bool { get set } -
Indicates if the
OfflineManagerhas finished restoring suspended downloads.Warning
Anyresumeorcancelactions triggered before this returnstrueare not guaranteed and might result in unexpected behaviour.Declaration
Objective-C
@property (nonatomic, readonly) BOOL areSuspendedDownloadsRestored;Swift
var areSuspendedDownloadsRestored: Bool { get } -
The delegate for the
OfflineManagerDeclaration
Objective-C
@property (nonatomic, weak) id<BMPOfflineManagerDelegate> _Nullable delegate; -
Unavailable
Undocumented
Declaration
Objective-C
- (instancetype)init NS_UNAVAILABLE; -
Unavailable
Undocumented
Declaration
Objective-C
+ (instancetype)new NS_UNAVAILABLE; -
Declaration
Objective-C
+ (nonnull instancetype)sharedInstance;Swift
class func sharedInstance() -> SelfReturn Value
The singleton instance of the BMPOfflineManager.
-
Has to be called in your AppDelegate’s
application(application:didFinishLaunchingWithOptions:)method to initialize handling of offline content.If the shared instance is already initialized, this method will not have any effect.
Declaration
Objective-C
+ (void)initializeOfflineManager;Swift
class func initializeOfflineManager() -
Has to be called in your AppDelegate’s
application(application:didFinishLaunchingWithOptions:)method to initialize handling of offline content.Initializes the shared instance with a given
OfflineConfig. If the shared instance is already initialized, this method will not have any effect.Declaration
Objective-C
+ (void)initializeOfflineManagerWithOfflineConfig: (nonnull BMPOfflineConfig *)offlineConfig;Swift
class func initializeOfflineManager(offlineConfig: BMPOfflineConfig)Parameters
offlineConfigThe
OfflineConfig -
Returns an
OfflineContentManagerinstance which can be used to manage offline content and offline DRM related tasks for the providedSourceConfig.The instance returned by this method will always be the same for the same
SourceConfig.This method will throw an error (or return
nilin ObjC) in case aSourceConfigis passed that is not supported for being downloaded. ASourceConfigis only valid for download when it’s configured using an HLS asset.Declaration
Objective-C
- (nullable id<BMPOfflineContentManager>) offlineContentManagerForSourceConfig:(nonnull BMPSourceConfig *)sourceConfig error:(NSError *_Nullable *_Nullable)error;Parameters
sourceConfigA
SourceConfigfor which theOfflineContentMangeris requested.Return Value
OfflineContentManagerinstance for the providedSourceConfig@throws an error if the providedSourceConfigis not supported. -
Returns an
OfflineContentManagerinstance which can be used to manage offline content and offline DRM related tasks for the providedSourceConfig.The provided
identifierwill be used to create a folder containing needed resources for the offline content.The instance returned by this method will always be the same for the same
identifier.This method will throw an error (or return
nilin ObjC) in case aSourceConfigis passed that is not supported for being downloaded. ASourceConfigis only valid for download when it’s configured using an HLS asset.Warning
If anOfflineContentManageris acquired using this method, subsequent calls to any content related API on theOfflineManagerare not supported, meaning they could result in unexpected behaviour.Declaration
Objective-C
- (nullable id<BMPOfflineContentManager>) offlineContentManagerForSourceConfig:(nonnull BMPSourceConfig *)sourceConfig identifier:(nonnull NSString *)identifier error:(NSError *_Nullable *_Nullable)error;Parameters
sourceConfigA
SourceConfigfor which theOfflineContentMangeris requested.identifierA unique identifier for the given
SourceConfigwhich must not change once provided.Return Value
OfflineContentManagerinstance for the providedSourceConfig@throws an error if the providedSourceConfigis not supported. -
Deprecated
Use OfflineContentManager.offlineState instead
Returns the offline state for the given BMPSourceConfig.
Declaration
Objective-C
- (BMPOfflineState)offlineStateForSourceConfig: (nonnull BMPSourceConfig *)sourceConfig;Swift
func offlineState(for sourceConfig: SourceConfig) -> OfflineStateParameters
sourceConfigA BMPSourceConfig instance for which the offline state should be determined.
Return Value
The offline state for the given BMPSourceConfig.
-
Deprecated
Use OfflineContentManager.deleteOfflineData() instead
Deletes the offline stored media data associated with the given BMPSourceConfig. Calling this method is only valid when offlineStateForSourceConfig: for the same BMPSourceConfig instance returns BMPOfflineStateDownloaded.
Declaration
Objective-C
- (void)deleteOfflineDataForSourceConfig: (nonnull BMPSourceConfig *)sourceConfig;Swift
func deleteOfflineData(for sourceConfig: SourceConfig)Parameters
sourceConfigA BMPSourceConfig instance for which the offline data should be deleted.
-
Deprecated
Use OfflineContentManager.fetchAvailableTracks() instead
Fetches which tracks are available for download. When finished, BMPOfflineManagerListener’s didFetchAvailableTracks:: method is called.
Declaration
Objective-C
- (void)fetchAvailableTracksForSourceConfig: (nonnull BMPSourceConfig *)sourceConfig;Swift
func fetchAvailableTracks(for sourceConfig: SourceConfig)Parameters
sourceConfigA BMPSourceConfig instance for which the available tracks should be fetched.
-
Deprecated
Use OfflineContentManager.download() instead
Downloads the media data associated with the given BMPSourceConfig. The highest media bitrate will be selected for download by default. If you want to specify which bitrate should be selected for download, use downloadSourceConfig:minimumBitrate:.
Calling this method is only valid when offlineStateForSourceConfig: for the same BMPSourceConfig instance returns BMPOfflineStateNotDownloaded.
Declaration
Objective-C
- (void)downloadSourceConfig:(nonnull BMPSourceConfig *)sourceConfig;Swift
func download(sourceConfig: SourceConfig)Parameters
sourceConfigA BMPSourceConfig instance for which the media data should be downloaded.
-
Deprecated
Use OfflineContentManager.download(downloadConfig:) instead
Downloads the media data associated with the given BMPSourceConfig. Calling this method is only valid when offlineStateForSourceConfig: for the same BMPSourceConfig instance returns BMPOfflineStateNotDownloaded.
Declaration
Objective-C
- (void)downloadSourceConfig:(nonnull BMPSourceConfig *)sourceConfig downloadConfig:(nonnull BMPDownloadConfig *)downloadConfig;Swift
func download(sourceConfig: SourceConfig, downloadConfig: DownloadConfig)Parameters
sourceConfigA BMPSourceConfig instance for which the media data should be downloaded.
downloadConfigThe BMPDownloadConfig used for this download
-
Deprecated
Use OfflineContentManager.download(tracks:downloadConfig:) instead
Downloads the media data associated with the given BMPSourceConfig depending on the given BMPOfflineTrackSelection. Calling this method is only valid when offlineStateForSourceConfig: for the same BMPSourceConfig instance returns BMPOfflineStateNotDownloaded.
Declaration
Objective-C
- (void)downloadSourceConfig:(nonnull BMPSourceConfig *)sourceConfig tracks:(nonnull BMPOfflineTrackSelection *)tracks downloadConfig:(nonnull BMPDownloadConfig *)downloadConfig;Swift
func download(sourceConfig: SourceConfig, tracks: BMPOfflineTrackSelection, downloadConfig: DownloadConfig)Parameters
sourceConfigA BMPSourceConfig instance for which the media data should be downloaded.
tracksa BMPOfflineTrackSelection specifying which tracks to download
downloadConfigThe BMPDownloadConfig used for this download
-
Deprecated
Use OfflineContentManager.cancelDownload() instead
Cancels all running download tasks associated with the given BMPSourceConfig and deletes the partially downloaded content from disk. Calling this method is only valid when offlineStateForSourceConfig: for the same BMPSourceConfig instance returns BMPOfflineStateDownloading or BMPOfflineStateSuspended.
Declaration
Objective-C
- (void)cancelDownloadForSourceConfig:(nonnull BMPSourceConfig *)sourceConfig;Swift
func cancelDownload(for sourceConfig: SourceConfig)Parameters
sourceConfigA BMPSourceConfig instance for which all associated running download tasks should be cancelled.
-
Deprecated
Use OfflineContentManager.suspendDownload() instead
Suspends all running download tasks associated with the given BMPSourceConfig. Calling this method is only valid when offlineStateForSourceConfig: for the same BMPSourceConfig instance returns BMPOfflineStateDownloading. The download can be resumed by calling resumeDownloadForSourceConfig:. Not data is deleted when calling this method.
Declaration
Objective-C
- (void)suspendDownloadForSourceConfig:(nonnull BMPSourceConfig *)sourceConfig;Swift
func suspendDownload(for sourceConfig: SourceConfig)Parameters
sourceConfigA BMPSourceConfig instance for which all associated running download tasks should be suspended.
-
Deprecated
Use OfflineContentManager.resumeDownload() instead
Resumes all suspended download tasks associated with the given BMPSourceConfig. Calling this method is only valid when offlineStateForSourceConfig: for the same BMPSourceConfig instance returns BMPOfflineStateSuspended.
Declaration
Objective-C
- (void)resumeDownloadForSourceConfig:(nonnull BMPSourceConfig *)sourceConfig;Swift
func resumeDownload(for sourceConfig: SourceConfig)Parameters
sourceConfigA BMPSourceConfig instance for which all associated suspended download tasks should be resumed.
-
Deprecated
Use OfflineContentManager.syncOfflineDrmLicenseInformation() instead
Updates the stored DRM license information (e.g. expiration dates) by querying the KSM. The device needs to be online for this. The FairPlayConfig#prepareOfflineDrmLicenseInformation block is called after the KSM was queried successfully.
Declaration
Objective-C
- (void)syncOfflineDrmLicenseInformationForSourceConfig: (nonnull BMPSourceConfig *)sourceConfig;Swift
func syncOfflineDrmLicenseInformation(for sourceConfig: SourceConfig) -
Deprecated
Use OfflineContentManager.offlineDrmLicenseInformation instead
Returns information about the offline DRM license for a given SourceConfig, e.g. the remaining license duration. The device does not need to be online for this.
Declaration
Objective-C
- (nonnull BMPDrmLicenseInformation *) offlineDrmLicenseInformationForSourceConfig: (nonnull BMPSourceConfig *)sourceConfig;Swift
func offlineDrmLicenseInformation(for sourceConfig: SourceConfig) -> BMPDrmLicenseInformationParameters
sourceConfigA BMPSourceConfig instance for which the DRM license information should be returned.
-
Deprecated
Use OfflineContentManager.renewOfflineLicense() instead
Renews the already downloaded DRM license for a given SourceConfig. When successfully finished, BMPOfflineManagerListener’s offlineManagerDidRenewOfflineLicense: method is called. In case the license renewal fails an according error is passed via the listener’s offlineManager:didFailWithError: method.
NOTE: The EXT-X-SESSION-KEY has to be present in the master playlist for this to work properly.
Declaration
Objective-C
- (void)renewOfflineLicenseForSourceConfig: (nonnull BMPSourceConfig *)sourceConfig;Swift
func renewOfflineLicense(for sourceConfig: SourceConfig)Parameters
sourceConfigA BMPSourceConfig instance for which the DRM license should be renewed.
-
Deprecated
Use OfflineContentManager.createOfflineSourceConfig() instead
Creates and returns a BMPOfflineSourceConfig which should be used with a BMPPlayer instance when playback of offline content is desired.
Note: When intending to create an OfflineSourceConfig for DRM protected content, the according DrmConfig needs to be applied to the passed sourceConfig before creating the OfflineSourceConfig.
Declaration
Objective-C
- (nullable BMPOfflineSourceConfig *) createOfflineSourceConfigForSourceConfig: (nonnull BMPSourceConfig *)sourceConfig restrictedToAssetCache:(BOOL)restrictedToAssetCache;Swift
func createOfflineSourceConfig(for sourceConfig: SourceConfig, restrictedToAssetCache: Bool) -> OfflineSourceConfig?Parameters
sourceConfigA BMPSourceConfig instance for which a new BMPOfflineSourceConfig instance should be created
restrictedToAssetCacheWhether or not the player should restrict playback only to audio, video and subtitle tracks which are stored offline on the device. This has to be set to YES if the device has no network access.
Return Value
A BMPOfflineSourceConfig which can be used with a BMPPlayer instance for offline playback.
-
Deprecated
Use OfflineContentManager.add(listener:) instead
Adds a listener to the BMPOfflineManager.
Declaration
Objective-C
- (void)addListener:(nonnull id<BMPOfflineManagerListener>)listener forSourceConfig:(nonnull BMPSourceConfig *)sourceConfig;Parameters
listenerThe listener to add.
sourceConfigThe BMPSourceConfig instance for which the listener should be added.
-
Deprecated
Use OfflineContentManager.remove(listener:) instead
Removes a listener from the BMPOfflineManager.
Declaration
Objective-C
- (void)removeListener:(nonnull id<BMPOfflineManagerListener>)listener forSourceConfig:(nonnull BMPSourceConfig *)sourceConfig;Parameters
listenerThe listener to remove.
sourceConfigThe BMPSourceConfig instance for which the listener should be removed.
-
Should be called from your AppDelegate when application(application:handleEventsForBackgroundURLSession:completionHandler:) is called by the system.
Declaration
Objective-C
- (void)addCompletionHandler:(nonnull void (^)(void))completionHandler forIdentifier:(nonnull NSString *)identifier;Swift
func add(completionHandler: @escaping () -> Void, for identifier: String)Parameters
completionHandlerThe completion handler which is provided by the system.
identifierThe identifier which is provided by the system.
-
Deprecated
Use OfflineContentManager.offlineState == .downloaded instead
Can be used to determine if the BMPSourceConfig is playable without a network connection.
Declaration
Objective-C
- (BOOL)isSourceConfigPlayableOffline:(nonnull BMPSourceConfig *)sourceConfig;Swift
func isPlayableOffline(sourceConfig: SourceConfig) -> BoolParameters
sourceConfigA BMPSourceConfig instance for which the state should be determined.
Return Value
YES, if the BMPSourceConfig instance is playable without a network connection, NO otherwise.
-
Deprecated
Use OfflineContentManager.usedStorage instead
Returns how many bytes of storage are used by the offline content.
This can be used to get the current storage for in-progress downloads.
Declaration
Objective-C
- (long)usedStorageForSourceConfig:(nonnull BMPSourceConfig *)sourceConfig;Swift
func usedStorage(for sourceConfig: SourceConfig) -> IntParameters
sourceConfigA BMPSourceConfig instance for which the storage size in bytes should be calculated.
Return Value
How many bytes of storage are used by the offline content.
BMPOfflineManager Class Reference