Class: shaka.offline.Storage

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:
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
stream shakaExtern.Stream
startTime number
callback !function(shaka.media.SegmentReference)
Source:

(private, static) getAllSegmentIds_(manifest) → (non-null) {Array.<number>}

Parameters:
Name Type Description
manifest shakaExtern.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
config Object 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
originalManifestUri string
metadata Object
Source:
Returns:
Type
shakaExtern.ManifestDB

(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
period shakaExtern.Period
Source:
Returns:
Type
shakaExtern.PeriodDB

(private) createSegmentIndex_(manifest) → (non-null) {Promise}

Calls createSegmentIndex for all streams in the manifest.
Parameters:
Name Type Description
manifest shakaExtern.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
period shakaExtern.Period
stream shakaExtern.Stream
estimatedStreamBandwidth number
opt_variantId number <optional>
Source:
Returns:
Type
shakaExtern.StreamDB

(private) defaultConfig_() → {shakaExtern.OfflineConfiguration}

Source:
Returns:
Type
shakaExtern.OfflineConfiguration

(private) defaultTrackSelect_(tracksnon-null) → (non-null) {Array.<shakaExtern.Track>}

The default track selection function.
Parameters:
Name Type Description
tracks Array.<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
manifestUri string
manifest shakaExtern.Manifest
appMetadata Object
drmEngine shaka.media.DrmEngine
Source:
Returns:
Type
Promise.<shakaExtern.StoredContent>

(private) filterAllPeriods_(periodsnon-null)

Parameters:
Name Type Description
periods Array.<shakaExtern.Period>
Source:

(private) filterPeriod_(period)

Parameters:
Name Type Description
period shakaExtern.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
manifestUri string
onError function(*)
opt_manifestParserFactory shakaExtern.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
contentUri string
Source:
Returns:
Type
Promise

(private) removeByUrl_(offlineUrinon-null) → (non-null) {Promise}

Parameters:
Name Type Description
offlineUri string
Source:
Returns:
Type
Promise

(private) removeManifest_(manifestUri, manifestId, manifest) → (non-null) {Promise}

Parameters:
Name Type Description
manifestUri string
manifestId number
manifest shakaExtern.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
manifestUri string The URI of the manifest to store.
opt_appMetadata Object <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_manifestParserFactory shakaExtern.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>