Constructor
(export) new Storage(player)
This manages persistent offline data including storage, listing, and deleting
stored manifests. Playback of offline manifests are done through the Player
using a 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, non-null) segmentsFromStore_ :Array.<number>
A list of segment ids for all the segments that were added during the
current store. If the store fails or is aborted, these need to be
removed from storage.
Type:
- Array.<number>
- Source:
Methods
(static) defaultTrackSelect(preferredAudioLanguage, tracksnon-null) → (non-null) {Array.<shakaExtern.Track>}
The default track selection function.
Parameters:
Name | Type | Description |
---|---|---|
preferredAudioLanguage |
string | |
tracks |
Array.<shakaExtern.Track> |
- Source:
Returns:
- Type
- Array.<shakaExtern.Track>
(export, static) deleteAll() → (non-null) {Promise}
Delete the on-disk storage and all the content it contains. This should not
be done in normal circumstances. Only do it when storage is rendered
unusable, such as by a version mismatch. No business logic will be run, and
licenses will not be released.
- Source:
Returns:
- Type
- Promise
(private, static) forEachSegment_(stream, startTime, callback)
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>
(private, static) getStreamSet_(manifest) → (non-null) {Array.<shakaExtern.Stream>}
Get a collection of streams that are in the manifest. This collection will
only have one instance of each stream (similar to a set).
Parameters:
Name | Type | Description |
---|---|---|
manifest |
shakaExtern.Manifest |
- Source:
Returns:
- Type
- Array.<shakaExtern.Stream>
(private, static) lookForSimilarTracks_(tracksnon-null) → {boolean}
Look to see if there are any tracks that are "too" similar to each other.
Parameters:
Name | Type | Description |
---|---|---|
tracks |
Array.<shakaExtern.Track> |
- Source:
Returns:
- Type
- boolean
(export, 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:
(export) 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_(downloadernon-null, storage, drmEnginenon-null, manifest, 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 |
---|---|---|
downloader |
shaka.offline.DownloadManager | |
storage |
shakaExtern.StorageCell | |
drmEngine |
shaka.media.DrmEngine | |
manifest |
shakaExtern.Manifest | |
originalManifestUri |
string | |
metadata |
Object |
- Source:
Returns:
(private) createPeriod_(downloadernon-null, storage, estimator, drmEnginenon-null, manifest, 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 |
---|---|---|
downloader |
shaka.offline.DownloadManager | |
storage |
shakaExtern.StorageCell | |
estimator |
shaka.offline.StreamBandwidthEstimator | |
drmEngine |
shaka.media.DrmEngine | |
manifest |
shakaExtern.Manifest | |
period |
shakaExtern.Period |
- Source:
Returns:
- Type
- shakaExtern.PeriodDB
(private) createRequest_(segment) → {shakaExtern.Request}
Parameters:
Name | Type | Description |
---|---|---|
segment |
shaka.media.SegmentReference | shaka.media.InitSegmentReference |
- Source:
Returns:
- Type
- shakaExtern.Request
(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_(downloadernon-null, storage, estimator, manifest, period, stream) → {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 | Description |
---|---|---|
downloader |
shaka.offline.DownloadManager | |
storage |
shakaExtern.StorageCell | |
estimator |
shaka.offline.StreamBandwidthEstimator | |
manifest |
shakaExtern.Manifest | |
period |
shakaExtern.Period | |
stream |
shakaExtern.Stream |
- Source:
Returns:
- Type
- shakaExtern.StreamDB
(export) 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) downloadManifest_(storage, drmnon-null, manifest, uri, metadatanon-null) → (non-null) {Promise.<shakaExtern.ManifestDB>}
Create a download manager and download the manifest.
Parameters:
Name | Type | Description |
---|---|---|
storage |
shakaExtern.StorageCell | |
drm |
shaka.media.DrmEngine | |
manifest |
shakaExtern.Manifest | |
uri |
string | |
metadata |
Object |
- Source:
Returns:
- Type
- Promise.<shakaExtern.ManifestDB>
(private) filterAllPeriods_(drmEnginenon-null, periodsnon-null)
Parameters:
Name | Type | Description |
---|---|---|
drmEngine |
shaka.media.DrmEngine | |
periods |
Array.<shakaExtern.Period> |
- Source:
(private) filterPeriod_(drmEnginenon-null, period)
Parameters:
Name | Type | Description |
---|---|---|
drmEngine |
shaka.media.DrmEngine | |
period |
shakaExtern.Period |
- Source:
(export) 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}>
(export) remove(contentUri) → (non-null) {Promise}
Removes the given stored content. This will also attempt to release the
licenses, if any.
Parameters:
Name | Type | Description |
---|---|---|
contentUri |
string |
- Source:
Returns:
- Type
- Promise
(private) removeFromDRM_(urinon-null, manifestDB) → (non-null) {Promise}
Parameters:
Name | Type | Description |
---|---|---|
uri |
shaka.offline.OfflineUri | |
manifestDB |
shakaExtern.ManifestDB |
- Source:
Returns:
- Type
- Promise
(private) removeFromStorage_(storage, urinon-null, manifest) → (non-null) {Promise}
Parameters:
Name | Type | Description |
---|---|---|
storage |
shakaExtern.StorageCell | |
uri |
shaka.offline.OfflineUri | |
manifest |
shakaExtern.ManifestDB |
- Source:
Returns:
- Type
- Promise
(private) requireSupport_()
Used by functions that need storage support to ensure that the current
platform has storage support before continuing. This should only be
needed to be used at the start of public methods.
- Source:
(export) store(uri, 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 |
---|---|---|---|
uri |
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>