Constructor
new Storage(player)
This manages persistent offline data including storage, listing, and deleting
stored manifests. Playback of offline manifests are done using Player
using the special URI (see shaka.offline.OfflineUri).
First, check support() to see if offline is supported by the platform.
Second, configure() the storage object with callbacks to your application.
Third, call store(), remove(), or list() as needed.
When done, call destroy().
Parameters:
| Name | Type | Description |
|---|---|---|
player |
shaka.Player | The player instance to pull configuration data from. |
- Implements:
- Source:
Members
-
(private, nullable) config_ :shakaExtern.OfflineConfiguration
-
Type:
- Source:
-
(private) downloadManager_ :shaka.offline.DownloadManager
-
Type:
- Source:
-
(private) drmEngine_ :shaka.media.DrmEngine
-
Type:
- Source:
-
(private) firstPeriodTracks_ :Array.<shakaExtern.Track>
-
Type:
- Array.<shakaExtern.Track>
- Source:
-
(private, nullable) manifest_ :shakaExtern.Manifest
-
Type:
- Source:
-
(private, nullable) pendingContent_ :shakaExtern.StoredContent
-
The stored content for the manifest that storage is currently downloading. If this is null, it means that storage is not downloading a manifest.
Type:
- Source:
-
(private) player_ :shaka.Player
-
Type:
- Source:
-
(private) storageEngine_ :shaka.offline.IStorageEngine
-
Type:
- Source:
-
(private) storeInProgress_ :boolean
-
Type:
- boolean
- Source:
Methods
-
(private, static) forEachSegment_(stream, startTime, callbacknon-null)
-
Parameters:
Name Type Description streamshakaExtern.Stream startTimenumber callback!function(shaka.media.SegmentReference) - Source:
-
(private, static) getAllSegmentIds_(manifest) → (non-null) {Array.<number>}
-
Parameters:
Name Type Description manifestshakaExtern.ManifestDB - Source:
Returns:
- Type
- Array.<number>
-
(static) support() → {boolean}
-
Gets whether offline storage is supported. Returns true if offline storage is supported for clear content. Support for offline storage of encrypted content will not be determined until storage is attempted.
- Source:
Returns:
- Type
- boolean
-
(private) checkDestroyed_()
-
Throws an error if the object is destroyed.
- Source:
-
(private) cleanup_() → (non-null) {Promise}
-
Cleans up the current store and destroys any objects. This object is still usable after this.
- Source:
Returns:
- Type
- Promise
-
configure(confignon-null)
-
Sets configuration values for Storage. This is not associated with Player.configure and will not change Player. There are two important callbacks configured here: one for download progress, and one to decide which tracks to store. The default track selection callback will store the largest SD video track. Provide your own callback to choose the tracks you want to store.
Parameters:
Name Type Description configObject This should follow the form of shakaExtern.OfflineConfiguration, but you may omit any field you do not wish to change. - Source:
-
(private) createOfflineManifest_(originalManifestUri, metadatanon-null) → {shakaExtern.ManifestDB}
-
Creates an offline 'manifest' for the real manifest. This does not store the segments yet, only adds them to the download manager through createPeriod_.
Parameters:
Name Type Description originalManifestUristring metadataObject - Source:
Returns:
-
(private) createPeriod_(period) → {shakaExtern.PeriodDB}
-
Converts a manifest Period to a database Period. This will use the current configuration to get the tracks to use, then it will search each segment index and add all the segments to the download manager through createStream_.
Parameters:
Name Type Description periodshakaExtern.Period - Source:
Returns:
- Type
- shakaExtern.PeriodDB
-
(private) createSegmentIndex_(manifest) → (non-null) {Promise}
-
Calls createSegmentIndex for all streams in the manifest.
Parameters:
Name Type Description manifestshakaExtern.Manifest - Source:
Returns:
- Type
- Promise
-
(private) createStream_(period, stream, estimatedStreamBandwidth, opt_variantIdopt) → {shakaExtern.StreamDB}
-
Converts a manifest stream to a database stream. This will search the segment index and add all the segments to the download manager.
Parameters:
Name Type Attributes Description periodshakaExtern.Period streamshakaExtern.Stream estimatedStreamBandwidthnumber opt_variantIdnumber <optional>
- Source:
Returns:
- Type
- shakaExtern.StreamDB
-
(private) defaultConfig_() → {shakaExtern.OfflineConfiguration}
-
- Source:
Returns:
-
(private) defaultTrackSelect_(tracksnon-null) → (non-null) {Array.<shakaExtern.Track>}
-
The default track selection function.
Parameters:
Name Type Description tracksArray.<shakaExtern.Track> - Source:
Returns:
- Type
- Array.<shakaExtern.Track>
-
destroy() → (non-null) {Promise}
-
Destroys the object, releasing all resources and shutting down all operations. Returns a Promise which is resolved when destruction is complete. This Promise should never be rejected.
- Implements:
- Source:
Returns:
- Type
- Promise
-
(private) downloadAndStoreManifest_(manifestUri, manifest, appMetadatanon-null, drmEnginenon-null) → (non-null) {Promise.<shakaExtern.StoredContent>}
-
Parameters:
Name Type Description manifestUristring manifestshakaExtern.Manifest appMetadataObject drmEngineshaka.media.DrmEngine - Source:
Returns:
- Type
- Promise.<shakaExtern.StoredContent>
-
(private) filterAllPeriods_(periodsnon-null)
-
Parameters:
Name Type Description periodsArray.<shakaExtern.Period> - Source:
-
(private) filterPeriod_(period)
-
Parameters:
Name Type Description periodshakaExtern.Period - Source:
-
(private) initIfNeeded_() → (non-null) {Promise}
-
Initializes the IStorageEngine if it is not already.
- Source:
Returns:
- Type
- Promise
-
list() → (non-null) {Promise.<!Array.<shakaExtern.StoredContent>>}
-
Lists all the stored content available.
- Source:
Returns:
A Promise to an array of structures representing all stored content. The "offlineUri" member of the structure is the URI that should be given to Player.load() to play this piece of content offline. The "appMetadata" member is the appMetadata argument you passed to store().- Type
- Promise.<!Array.<shakaExtern.StoredContent>>
-
loadInternal(manifestUri, onError, opt_manifestParserFactoryopt, non-null) → (non-null) {Promise.<{manifest: shakaExtern.Manifest, drmEngine: !shaka.media.DrmEngine}>}
-
Loads the given manifest, parses it, and constructs the DrmEngine. This stops the manifest parser. This may be replaced by tests.
Parameters:
Name Type Attributes Description manifestUristring onErrorfunction(*) opt_manifestParserFactoryshakaExtern.ManifestParser.Factory <optional>
- Source:
Returns:
- Type
- Promise.<{manifest: shakaExtern.Manifest, drmEngine: !shaka.media.DrmEngine}>
-
remove(contentUri) → (non-null) {Promise}
-
Removes the given stored content.
Parameters:
Name Type Description contentUristring - Source:
Returns:
- Type
- Promise
-
(private) removeByUrl_(offlineUrinon-null) → (non-null) {Promise}
-
Parameters:
Name Type Description offlineUristring - Source:
Returns:
- Type
- Promise
-
(private) removeManifest_(manifestUri, manifestId, manifest) → (non-null) {Promise}
-
Parameters:
Name Type Description manifestUristring manifestIdnumber manifestshakaExtern.ManifestDB - Source:
Returns:
- Type
- Promise
-
store(manifestUri, opt_appMetadataopt, non-null, opt_manifestParserFactoryopt, non-null) → (non-null) {Promise.<shakaExtern.StoredContent>}
-
Stores the given manifest. If the content is encrypted, and encrypted content cannot be stored on this platform, the Promise will be rejected with error code 6001, REQUESTED_KEY_SYSTEM_CONFIG_UNAVAILABLE.
Parameters:
Name Type Attributes Description manifestUristring The URI of the manifest to store. opt_appMetadataObject <optional>
An arbitrary object from the application that will be stored along-side the offline content. Use this for any application-specific metadata you need associated with the stored content. For details on the data types that can be stored here, please refer to https://goo.gl/h62coS opt_manifestParserFactoryshakaExtern.ManifestParser.Factory <optional>
- Source:
Returns:
A Promise to a structure representing what was stored. The "offlineUri" member is the URI that should be given to Player.load() to play this piece of content offline. The "appMetadata" member is the appMetadata argument you passed to store().- Type
- Promise.<shakaExtern.StoredContent>