Class OfflineStoreManager

java.lang.Object
com.brightcove.player.store.BaseStore
com.brightcove.player.edge.OfflineStoreManager

public class OfflineStoreManager extends BaseStore
Store manager can be used to persist data into an application specific private database.
  • Method Details

    • getInstance

      public static OfflineStoreManager getInstance(@NonNull android.content.Context context)
      Gets reference to the single instance of OfflineStoreManager
      Parameters:
      context - reference to the host application context.
      Returns:
      reference to the OfflineStoreManager
    • refreshEntity

      @Nullable public <E extends IdentifiableEntity> E refreshEntity(@Nullable E entity)
      Refresh the given entity. This refreshes the already loaded properties in the entity. If no properties are loaded then the default properties will be loaded.
      Overrides:
      refreshEntity in class BaseStore
      Type Parameters:
      E - the expected type of the entity;
      Parameters:
      entity - reference to the entity to be refreshed.
      Returns:
      null if the entity is null or if it does not exist in the store, otherwise reference to the updated entity
    • saveEntity

      public <T extends IdentifiableEntity> T saveEntity(@NonNull T entity)
      Inserts or updates the given entity.
      Overrides:
      saveEntity in class BaseStore
      Parameters:
      entity - the entity to be save.
      Returns:
      the updated the entity.;
    • updateDownloadRequestIdList

      @Nullable public com.brightcove.player.store.OfflineVideo updateDownloadRequestIdList(@NonNull String videoId, @Nullable List<Long> requestIdList, long estimatedSize)
      Updates the entity with given unique video identifier to save the current list of download request identifiers.
      Parameters:
      videoId - the unique video identifier.
      requestIdList - a list of download request identifiers.
      Returns:
      null if an entity with specified video identifier was found, otherwise reference to the updated entity.
    • saveOfflineVideo

      public com.brightcove.player.store.OfflineVideo saveOfflineVideo(@NonNull Video video, @NonNull File downloadDirectory, @NonNull com.brightcove.player.store.DownloadRequestSet requestSet)
      Saves the offline video information into the store.
      Parameters:
      video - the video information to be saved.
      downloadDirectory - the download directory for this video.
      requestSet - the download request set related to this video.
      Returns:
      reference to the newly created entity.
    • saveOfflineVideo

      @NonNull public com.brightcove.player.store.OfflineVideo saveOfflineVideo(Video video)
      Updates the entity with given unique video identifier to save the video metadata object, while retaining the previously saved license information.
      Parameters:
      video - the video to be saved.
      Returns:
      reference to the updated entity.
      See Also:
    • saveOfflineLicense

      @NonNull public com.brightcove.player.store.OfflineVideo saveOfflineLicense(@NonNull Video video)
      Updates the entity with given unique video identifier to save the video license information.
      Parameters:
      video - the video to be saved.
      Returns:
      reference to the updated entity.
      See Also:
    • findOfflineVideo

      @Nullable public com.brightcove.player.store.OfflineVideo findOfflineVideo(@NonNull String videoId)
      Finds the first offline video entity with the given video identifier.
      Parameters:
      videoId - the unique video identifier.
      Returns:
      null if there is no offline entity with the given identifier, otherwise reference to first matching entity.
    • findAllOfflineVideo

      @NonNull public List<com.brightcove.player.store.OfflineVideo> findAllOfflineVideo()
      Finds all offline video entities.
      Returns:
      a list of offline video entities.
    • findAllOfflineVideo

      @NonNull public List<com.brightcove.player.store.OfflineVideo> findAllOfflineVideo(int status)
      Finds all offline video entities with the specified status
      Returns:
      a list of offline video entities.
    • deleteOfflineVideo

      public boolean deleteOfflineVideo(@NonNull String videoId)
      Deletes the first offline video entity with the given video identifier.
      Parameters:
      videoId - the unique video identifier.
      Returns:
      true if a matching entity was found and deleted, otherwise false.
    • createDownloadRequestSet

      @NonNull public com.brightcove.player.store.DownloadRequestSet createDownloadRequestSet(@Nullable RequestConfig requestConfig, long estimatedSize)
      Creates a new blank download request set.
      Returns:
      reference to the newly created entity
    • addDownloadRequests

      @NonNull public com.brightcove.player.store.DownloadRequestSet addDownloadRequests(@NonNull com.brightcove.player.store.DownloadRequestSet requestSet, @NonNull IDownloadManager.IRequest... requests)
      Creates a new blank download request set.
      Returns:
      reference to the newly created entity
    • findDownloadRequestSetByKey

      @Nullable public com.brightcove.player.store.DownloadRequestSet findDownloadRequestSetByKey(@NonNull Long key)
      Finds a download request set with the specified unique key.
      Parameters:
      key - the primary key of the request set.
      Returns:
      null if the entity was not found, otherwise reference to the entity.
    • findOfflineAssetUri

      @Nullable public android.net.Uri findOfflineAssetUri(@Nullable android.net.Uri uri)
      Finds the local URI of a remote asset that has been downloaded successfully.
      Parameters:
      uri - the remote URI to the asset.
      Returns:
      null if the asset is not available, otherwise URI to the local copy of the asset.
    • findDownloadRequestSets

      public Collection<com.brightcove.player.store.DownloadRequestSet> findDownloadRequestSets(@NonNull Long... requestIds)
      Finds the download request sets to which the given requests belong to.
      Parameters:
      requestIds - an array of one or more download requests.
      Returns:
      a list of download request sets.
    • deleteDownloadRequestSet

      public boolean deleteDownloadRequestSet(@NonNull Long key)
      Deletes the specified request set from the store.
      Parameters:
      key - the primary key of the request set to be deleted.
      Returns:
      true if a matching entity was found and deleted, otherwise false.
    • updateDownloadRequestStatusByDownloadId

      @Nullable public com.brightcove.player.store.DownloadRequest updateDownloadRequestStatusByDownloadId(@NonNull Long downloadId, int statusCode, int reasonCode, long bytesDownloaded, long actualSize, boolean updateParentRecord)
      Updates the status of download request.
      Parameters:
      downloadId - the unique identifier of the download request that caused the status change.
      statusCode - the new status of the download.
      reasonCode - the reason code for the new status, if any.
      bytesDownloaded - the number of bytes downloaded so far.
      actualSize - the total size of the download.
      updateParentRecord - true to update the DownloadRequestSet parent record.
      Returns:
      reference to the updated entity if it was found and updated, otherwise null.
    • updateDownloadRequestSetStatus

      public boolean updateDownloadRequestSetStatus(com.brightcove.player.store.DownloadRequestSet requestSet, int statusCode, int reasonCode, com.brightcove.player.store.DownloadRequest downloadRequest, boolean evaluateAllSegments)
      Updates the status of Download Request Set.
      Parameters:
      requestSet - the Download Request Set
      statusCode - the new status of the download segment.
      reasonCode - the reason code for the new status, if any.
      downloadRequest - the new segment Download Request
      evaluateAllSegments - if true, it makes sure to evaluate all download request segments to get the overall status.
      Returns:
      true if updated.
    • pauseDownloadRequestSet

      @NonNull public List<com.brightcove.player.store.DownloadRequest> pauseDownloadRequestSet(@NonNull Long key)
      Marks a download request set as paused.
      Parameters:
      key - the primary key of the request set to be paused.
      Returns:
      a list of download requests that have to be removed from the active download queue.
    • resumeDownloadRequestSet

      @Nullable public com.brightcove.player.store.DownloadRequestSet resumeDownloadRequestSet(@NonNull Long key)
      Marks a download request set as waiting to be queued.
      Parameters:
      key - the primary key of the request set to be paused.
      Returns:
      null if the request set was not found, otherwise reference to the updated request set.
    • updateDownloadId

      public boolean updateDownloadId(@NonNull Long key, Long downloadId)
      Sets the download identifier for the request with the specified primary key.
      Parameters:
      key - the primary key of the request to be updated.
      downloadId - the unique identifier to the download request in the DownloadManager
      Returns:
      true if the entity was found and updated, otherwise false.
    • changeDownloadIdentifier

      @Nullable public com.brightcove.player.store.OfflineVideo changeDownloadIdentifier(@NonNull Video video)
      Changes the download identifier associated with given video. This method is intended for internal use only. Please do not call this in the application project.
      Parameters:
      video - reference to the video.
      Returns:
      the offline video entity associated with this video, if any.
    • markRequestSetForRemoval

      @NonNull public List<com.brightcove.player.store.DownloadRequest> markRequestSetForRemoval(@NonNull Long key)
      Marks the specified request set for removal. A request set that has been marked for removal will not be queued or checked for further status changes. Any download requests in the set that has been queued already will be removed. The request set itself will be deleted once all the requests have been removed.
      Parameters:
      key - the primary key of the request set to be updated.
      Returns:
      a list download requests that must be removed from the download queue.
    • findDownloadsToBeQueued

      @NonNull public List<com.brightcove.player.store.DownloadRequest> findDownloadsToBeQueued(int batchSize, boolean excludeWifiOnly)
      Fetches a list of download requests that not have been queued for download by the DownloadManager.
      Parameters:
      batchSize - the maximum number of entities to fetch.
      excludeWifiOnly - true if the requests that allowed only on wifi networks must be excluded, otherwise false.
      Returns:
      a list of pending download requests.
    • isCurrentDownloadBatchInProgress

      public boolean isCurrentDownloadBatchInProgress()
      Checks if the current set of download request are still being processed.
      Returns:
      true if the current set of download request are still being processed, otherwise false.
    • countDownloadRequestsInState

      public int countDownloadRequestsInState(@NonNull Long requestSetKey, int statusCode)
      Counts the download requests belonging to a DownloadRequestSet with the specified status code.
      Parameters:
      requestSetKey - the Download Request Set key.
      statusCode - the status code.
      Returns:
      the count.
    • isDownloadCompleted

      public boolean isDownloadCompleted(@NonNull Long requestSetKey)
      Checks if the DownloadRequestSet is completed.
      Parameters:
      requestSetKey - the Download Request Set key.
      Returns:
      true is download is completed.
    • findCurrentDownloadBatchInProgress

      public List<com.brightcove.player.store.DownloadRequest> findCurrentDownloadBatchInProgress(int batchSize)
      Finds the current set of download request which are still being processed.
      Parameters:
      batchSize - the maximum number of entities to fetch
      Returns:
      a list of download requests
    • findCurrentDownloadRequestSetInProgress

      public List<com.brightcove.player.store.DownloadRequestSet> findCurrentDownloadRequestSetInProgress()
      Finds the current set of download request set which are still being processed.
      Returns:
      a list of download request sets
    • toVideoList

      public static List<Video> toVideoList(@NonNull List<com.brightcove.player.store.OfflineVideo> entityList)
      Converts the given list of OfflineVideo objects into a list of Video objects.
      Parameters:
      entityList - the list to be converted.
      Returns:
      the converted list.